I used to manually download the jdk's, or install them using brew cask, and I would set 'bash alias' on my `~/bash_profile` to switch between different 'JAVA_HOME' etc etc.
I am already using brew & brew cask (official site here) & i recently started using 'CakeBrew'. So in order to install 3 different versions of java all you need to do is :
Step 1: Install JDK's using brew and brew caskbrew cask install caskroom/versions/java6
brew cask install caskroom/versions/java7
brew install java
After the installation check the following folder, you are expected to see the 3 different JDK folders.
Step 2: Install jenv> brew install jenv
Step 3: Add the 3 available JDK's to jenvjenv 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_131.jdk/Contents/Home
Step 4: Check if jenv has registered the different jdk'sjenv versions
Step 5: Use jenv to set up the JDK env either globally or the current shell--Setting java 1.8 for the shell
jenv shell 1.8
jenv shell 1.7
-- this sets it globally
jenv global 1.8
All done! You can switch different versions easily!
Watch out for now
- You can install a pre-release of java9 using ' brew cask install caskroom/versions/java9-beta' but it seems that the way it is installed and the paths are not compatible with what jenv expects so you can not jenv add 1.9 (for the time being)