12/31/2016 - 8:48 AM



Solution 1 - DIY

  • Install multiple JDK Uninstall jdk8, install jdk7, then reinstall jdk8.

  • To switch between them, add the following to .profile

export JAVA_8_HOME=$(/usr/libexec/java_home -v1.8)
export JAVA_7_HOME=$(/usr/libexec/java_home -v1.7)

alias java7='export JAVA_HOME=$JAVA_7_HOME'
alias java8='export JAVA_HOME=$JAVA_8_HOME'

#default java8
  • Then you can simply type java7 or java8 in a terminal to switch versions.

Solution 2 - Homebrew

Use homebrew-cask to install the versions of java, and use jenv to manage the installed versions of java

As seen on, these are the steps to follow.

  1. install homebrew
  2. install homebrew jenv
  3. install homebrew-cask
  4. install a specific java version using cask (see "homebrew-cask versions" paragraph below)
  5. add this version for jenv to manage it
  6. check the version is correctly managed by jenv

Repeat steps 4 to 6 for each version of java you need

homebrew-cask versions

Add the "caskroom/versions" tap to homebrew using:

brew tap caskroom/versions

Then you can look at all the versions available:

brew cask search java

Then you can install the version(s) you like:

brew cask install java7
brew cask install java6

And add them to be managed by jenv as usual.

jenv add <javaVersionPathHere>

I think this is the cleanest & simplest way to go about it.

Another important thing to note, as mentioned in Mac OS X 10.6.7 Java Path Current JDK confusing

For different types of JDKs or installations, you will have different paths

On Mac OS X Mavericks, I found as following:

  1. Built-in JRE default: /Library/Internet/Plug-Ins/JavaAppletPlugin.plugin/Contents/Home

  2. JDKs downloaded from Apple: /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home/

  3. JDKs downloaded from Oracle: /Library/Java/JavaVirtualMachines/jdk1.8.0_11.jdk/Contents/Home