by

Multiple JDK in Mac OSX 10.10 Yosemite

It is very common for developers to setup multiple JRE environment. Some developers prefer using VM to install another version of JDK and keeping the default version in their local, but i prefer to install multiple JRE in my local machine. Here's how i do it on my Mac.

1. Download and Install Java 1.6 updates

Get this link https://support.apple.com/kb/DL1572?locale=en_US

Install the package

2. Download Oracle JDK 7u79

The Java SE Development Kit 7u79 can be downloaded here http://www.oracle.com/technetwork/java/javase/downloads/jdk7-downloads-1880260.html

Install the package.

3. Now There are two Java Installed

Now there will be 2 java in the system.

  • Java 1.6 home:
    /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home
  • Java 1.7 home:
    /Library/Java/JavaVirtualMachines/jdk1.7.0_79.jdk/Contents/Home

4. Get Default JAVA_HOME

Mac OS has a command to quickly get JAVA_HOME path between versions. In terminal, you can exec this:

  • /usr/libexec/java_home -v 1.6
  • /usr/libexec/java_home -v 1.7
It will show the JAVA_HOME for each version. But not switching the default JRE

5. Quickly Switch Default JAVA_HOME

Open terminal, and type this:

java -version
Depending on your installation, the output could be different. Mine is:
java version "1.7.0_79"
Java(TM) SE Runtime Environment (build 1.7.0_79-b15)
Java HotSpot(TM) 64-Bit Server VM (build 24.79-b02, mixed mode)

Switch to Java 1.6

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

Switch to Java 1.7

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