Skip to content

Instantly share code, notes, and snippets.

@ntamvl
Last active February 21, 2024 11:12
Show Gist options
  • Star 99 You must be signed in to star a gist
  • Fork 29 You must be signed in to fork a gist
  • Save ntamvl/5f4dbaa8f68e6897b99682a395a44c2e to your computer and use it in GitHub Desktop.
Save ntamvl/5f4dbaa8f68e6897b99682a395a44c2e to your computer and use it in GitHub Desktop.
Install Multiple Java Versions on macOS High Sierra

Install Multiple Java Versions on macOS High Sierra

Install Homebrew Cask

On Mac, Homebrew is the de-facto package manager, and Homebrew Cask is the app manager. I’m going to use Cask to install Java 7 and 8.

Install Homebrew Cask first if you haven’t:

brew update
brew tap caskroom/cask
brew install brew-cask-completion

If your brew or cask is outdated, update and upgrade:

brew update && brew upgrade brew-cask-completion && brew cleanup && brew cask cleanup

Check if we already have JDK 6, 7, 8, 9 installed by Homebrew Cask:

brew tap caskroom/versions
brew cask info java6
brew cask info java7
brew cask info java8

To check JDK 9 (latest)

brew cask info java

Install Java 6, 7, 8, 9 (latest):

brew tap caskroom/versions
brew cask install java6
brew cask install java7
brew cask install java8

To install JDK 9 (latest)

brew cask install java

Check if we already have JDK 6, 7, 8, 9 installed by Homebrew Cask:

brew tap caskroom/versions
brew cask info java6
brew cask info java7
brew cask info java8

To check JDK 9 (latest)

brew cask info java

Enter jEnv

Now it is time to install jEnv:

brew install jenv

Add the following lines to ~/.bash_profile This will initialize jEnv.

Init jenv

if which jenv > /dev/null; then eval "$(jenv init -)"; fi

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/jdk1.7.0_79.jdk/Contents/Home/
jenv add /Library/Java/JavaVirtualMachines/jdk1.8.0_66.jdk/Contents/Home/

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

jenv versions

source: http://davidcai.github.io/blog/posts/install-multiple-jdk-on-mac/

@mitsuhisaT
Copy link

I have installed java9 and java 8.

After install brew-cask-completion,

brew cask reinstall java8
brew cask reinstall java

@MichelinMan
Copy link

Thank you!

@blcarlson01
Copy link

brew cask install java7 returns the following error "Error: Cask 'java7' is unavailable: No Cask with this name exists."

The only easy alternative I've found so far is "brew cask install caskroom/versions/zulu7" found on here: Homebrew/homebrew-cask-versions#3914

@SamCarlberg
Copy link

FYI Java 9 is no longer available from brew since the JDK 9 downloads require an Oracle account to access. Java 10 will most likely go the same way when 11 is released in a few weeks

@alexleone
Copy link

This will no longer work.

@devth
Copy link

devth commented Nov 5, 2018

Yep we're now stuck with 11. How to downgrade to 10?

@max-lobur
Copy link

caskroom/versions/java10 doesnt work anymore (mojave 10.14.1), so I had to jump back to java8 :(

max-lobur/dotfiles@19ddb89

@gbelanger
Copy link

Thanks a lot for this!

@UnsGentoals
Copy link

JAVA6_HOME=/usr/libexec/java_home -v 1.6
JAVA7_HOME=/usr/libexec/java_home -v 1.7
JAVA8_HOME=/usr/libexec/java_home -v 1.8

@rjesususa
Copy link

rjesususa commented Aug 12, 2019

I've tried now and received the following message:

Error: Cask 'java7' is unavailable: No Cask with this name exists. 

also tried with java-7 and it still doesn’t work . --'

@stalinkay
Copy link

@ZacSweers
Copy link

@stalinkay Adopt OpenJDK doesn't have java 7 artifacts

@mochadwi
Copy link

mochadwi commented Nov 21, 2019

Unfortunately, the homebrew community has deleted the Java Oracle casks and this instruction a bit outdated, please refer to this: https://gist.github.com/mochadwi/7036d164e5840361701ef90276d23af1

Sadly adopt openjdk 7 is not available

@TeemuKoivisto
Copy link

To install Java 7 (as required by Zeppelin notebook) I used: brew cask install zulu7

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment