I followed this thread to solve my problem, I have the same problem with a different version of JDK and for some reason it didn't work. I still get -bash: JAVA_HOME: command not found when I type JAVA_HOME to my terminal. I have JDK220.127.116.11 located at Library/Java/JavaVirtualMachines/jdk1.8.0_45.jdk/Contents/Home which I can access with /usr/libexec/java_home
echo "export JAVA_HOME=
/usr/libexec/java_home" >> ~/.profile
I do get "export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_45.jdk/Contents/Home" saved to ~/.profile, and I can check this using /usr/bin/open ~/.profile
But I do not understand why JAVA_HOME still doesn't work and I need this to install maven.
Best How To :
My ~/.bash_profile has this line in it, and it's been working fine.
This line basically says "run the program named /usr/libexec/java_home and export its output as a variable named JAVA_HOME."
I suggest opening your .profile or .bash_profile in a text editor rather than using echo statements to append new lines to it. That way you can see everything that's in the file and make sure other old lines in the file aren't causing you issues.
After you make a change to .bash_profile, make sure you open a new terminal window before testing it.
You can check the value of any environment variable (including JAVA_HOME) by simply echo'ing its value:
In my case the output of that echo command is: /Library/Java/JavaVirtualMachines/jdk1.8.0_40.jdk/Contents/Home