Olivier Refalo Olivier Refalo - 4 months ago 10
Java Question

Where is JAVA_HOME on OSX Yosemite (10.10), Mavericks (10.9), Mountain Lion (10.8) or OSX Lion (10.7)?

Java is an optional package on the latest versions of OSX.

Yet once installed it appears like the JAVA_HOME environment variable is not set properly.

Answer

With the Java optional package or Oracle JDK installed, adding one of the following lines to your ~/.bash_profile file will set the environment variable accordingly.

export JAVA_HOME="$(/usr/libexec/java_home -v 1.6)"
or
export JAVA_HOME="$(/usr/libexec/java_home -v 1.7)"
or
export JAVA_HOME="$(/usr/libexec/java_home -v 1.8)"

Update: added -v flag based on Jilles van Gurp response.