Java software for your computer, or the Java Runtime Environment, is also referred to as the Java Runtime, Runtime Environment, Runtime, JRE, Java Virtual Machine, Virtual Machine, Java VM, JVM, VM, Java plug-in, Java plugin, Java add-on or Java download. 3 things apply to your ENV variables in which JAVA_HOME should be. ENV is a scoped 'dictionary' which is instantiated/loaded with every process being started on an OS. It is generally loaded through SYSTEM config and USER config.
I know it has been a while for this question, but I just wanted to share the following piece of information that I came across today. You can use /usr/libexec/javahome -v to get the path you need for JAVAHOME. For instance, to get the path to the 1.7 JDK you can run /usr/libexec/javahome -v 1.7 and it will return the path to the JDK. In your.profile or.bashprofile just add export JAVAHOME=`/usr/libexec/javahome -v ` and you should be good.
Alternatively, try and convince the maintainers of java tools you use to make use of this method to get the version they need. To open '.bashprofile' type the following in terminal: nano /.bashprofile and add the following line to the file: export JAVAHOME=`/usr/libexec/javahome -v ` Press CTRL+X to exit the bash. Press 'Y' to save changes. To check whether the path has been added, type following in terminal: source /.bashprofile echo $JAVAHOME. Besides the settings for bash/ zsh terminal which are well covered by the other answers, if you want a permanent system environment variable for terminal + GUI applications (works for macOS Sierra; should work for El Capitan too): launchctl setenv JAVAHOME $(/usr/libexec/javahome -v 1.8) (this will set JAVAHOME to the latest 1.8 JDK, chances are you have gone through serveral updates e.g.
![Download Java_home For Mac Download Java_home For Mac](/uploads/1/2/5/6/125601671/202784481.jpg)
Javac 1.8.0101, javac 1.8.0131) Of course, change 1.8 to 1.7 or 1.6 (really?) to suit your need and your system.