List the current installed Java versions
$ /usr/libexec/java_home -V
Install the version desired
Apple provides their own version of 6 (Java for OS X 2015-001)
List the current installed Java versions
You should see the version installed
Matching Java Virtual Machines (2):
1.8.0_25, x86_64: "Java SE 8" /Library/Java/JavaVirtualMachines/jdk1.8.0_25.jdk/Contents/Home
1.7.0_45, x86_64: "Java SE 7" /Library/Java/JavaVirtualMachines/jdk1.7.0_45.jdk/Contents/Home
Select the version
$ export JAVA_HOME=`/usr/libexec/java_home -v 1.7`
Confirm the java version
$ export JAVA_HOME=`/usr/libexec/java_home -v 1.7`
$ java -version
java version "1.7.0_45"
Java(TM) SE Runtime Environment (build 1.7.0_45-b18)
Java HotSpot(TM) 64-Bit Server VM (build 24.45-b08, mixed mode)
Java HotSpot(TM) 64-Bit Server VM (build 20.65-b04-468, mixed mode)
Installing this as a handy function in ZSH
# Function that changes the JAVA_HOME variable to the given java version.
function jhome () {
export JAVA_HOME=$(/usr/libexec/java_home -v "$@")
echo "JAVA_HOME:" $JAVA_HOME
echo "java -version:"
java -version
}