Mac OS : Set $JAVA_HOME environment variable
In this tutorial, we will go through the steps to set $JAVA_HOME environment variable on latest or older Mac OSX.
Mac OSX 10.5 or later
In Mac OSX 10.5 or later, Apple recommends to set the $JAVA_HOME variable to /usr/libexec/java_home, just export $JAVA_HOME in file ~/.bash_profile or ~/.profile
$ vim ~/.bash_profile
export JAVA_HOME=$(/usr/libexec/java_home)
$ source .bash_profile
$ echo $JAVA_HOME