Install and Manage Multiple Versions of Java on OS X

After getting my new job roles of managing the transmission and data network in BdREN, I have run couple of Java based applications like Cisco Transport Controller (CTC), Adaptive Security Device Manager (ASDM), LAN Management System (LMS) etc. It’s wired that most of those applications performs best with different individual Java versions and mostly with older versions like CTC works better on Java 6, ASDM works better on Java 7 and the latest Java version is now 8.

After taking my new MacBook Air, it became a serious concerns to me running and managing multiple versions of Java on my MacOS until I found jEnv. jEnv allows you to switch to different versions of Java using simple commands.

First, I am going to use Homebew package manager and Homebrew Cask app manager to install Java 6, 7 and 8. After that, I’ll show how to manage different java versions using jEnv.

Homebrew Cask

Install Homebrew Cask if you don’t have it:

$ ruby -e “$(curl -fsSL”
$ brew update
$ brew tap caskroom/cask
$ brew install brew-cask

If your Homebrew Cask needs to be updated and upgraded:

$ brew update && brew upgrade brew-cask && brew cleanup && brew cask cleanup

Install jEnv using Homebrew

The simplest way to install jEnv is:

$ brew install jenv

Or, you can try using:

$ brew install

Create ~/.bash_profile and add the following lines there. This will initialize jEnv.

$ cd
$ touch .bash_profile
$ vi .bash_profile
# Init jenv
if which jenv > /dev/null; then eval $(jenv init -); fi

Now it’s installed, lets see what versions of Java it can find:

$ jenv versions
* system (set by /Users/ajones/.jenv/version)

For me, it only found the system Java but no other version is detected. The asterisk is the version currently selected.

I have the latest Java 8 already installed in my system as shown in the screenshot below.

Install Java 6, Java 7 and Java 8

As of today, Java 8 is the latest stable. But, some of the application that I need to use regularly needs older Java versions.

To install Java 6 in OS X, download it from the Apple webiste. It will be installed at /Library/Java/JavaVirtualMachines/ 

To install Java 7 run the following command:

$ brew cask install java7

If you run into permission issue, add sudo at the beginning of the above command.

To install Java 8 run the following command:

$ brew cask install java

All the versions will be installed at /Library/Java/JavaVirtualMachines/ 

Awals-MacBook-Air:~ awal$ cd /Library/Java/JavaVirtualMachines/
Awals-MacBook-Air:JavaVirtualMachines awal$ ls
1.6.0.jdk         jdk1.7.0_80.jdk          jdk1.8.0_144.jdk

Now, you can see multiple versions of Java installed in your MacOS. jEnv doesn’t install JDKs, so we have to tell jEnv where to look for them. Type these commands to register JDKs in jEnv (replace the minor and patch versions with yours):

$ jenv add /Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home/
$ jenv add /Library/Java/JavaVirtualMachines/jdk1.7.0_80.jdk/Contents/Home/
$ jenv add /Library/Java/JavaVirtualMachines/jdk1.8.0_144.jdk/Contents/Home/

After that, run this command to list all registered JDKs:

$ jenv versions

In my case the output shows like this:

Awals-MacBook-Air:~ awal$ jenv versions
* system (set by /Users/awal/.jenv/version)

As I need to set Java 6 as the default version for my MacBook Air, I set the global version to 1.6 with the command below:

$ jenv global oracle64-

The jEnv now shows the versions like this:

Awals-MacBook-Air:~ awal$ jenv versions
* oracle64- (set by /Users/awal/.jenv/version)


Configure local version (choose specific version per directory)

your-working:~ directory$ jenv local oracle64-

One Reply to “Install and Manage Multiple Versions of Java on OS X”

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.