In this article we show you how to set $JAVA_HOME environment variable on Mac OSX 10.5 or later.
Set the $JAVA_HOME variable to /usr/libexec/java_home, just export $JAVA_HOME in file ~/. bash_profile or ~/.profile as shown below
$ vim .bash_profile export JAVA_HOME=$(/usr/libexec/java_home) $ source .bash_profile $ echo $JAVA_HOME /Library/Java/JavaVirtualMachines/1.7.0.jdk/Contents/Home
Orginal Article from Mkyong.com