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.
Install Homebrew Cask if you don’t have it:
If your Homebrew Cask needs to be updated and upgraded:
Install jEnv using Homebrew
The simplest way to install jEnv is:
Or, you can try using:
Create ~/.bash_profile and add the following lines there. This will initialize jEnv.
Now it’s installed, lets see what versions of Java it can find:
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:
If you run into permission issue, add sudo at the beginning of the above command.
To install Java 8 run the following command:
All the versions will be installed at /Library/Java/JavaVirtualMachines/
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):
After that, run this command to list all registered JDKs:
In my case the output shows like this:
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:
The jEnv now shows the versions like this:
Configure local version (choose specific version per directory)