The cleanest way to manage multiple java versions on Mac is to use Homebrew.
And within Homebrew, use:
homebrew-caskto install the versions of javajenvto manage the installed versions of java
As seen on http://hanxue-it.blogspot.ch/2014/05/installing-java-8-managing-multiple.html , these are the steps to follow.
- install homebrew
- install homebrew jenv
- install homebrew-cask
- install a specific java version using cask (see "homebrew-cask versions" paragraph below)
- add this version for jenv to manage it
- 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 homebrew/cask-versions tap to homebrew using:
Copybrew tap homebrew/cask-versions
Then you can look at all the versions available by searching for Eclipse temurin, more details here
Copybrew search temurin
Then you can install the version(s) you like, though version 7 no longer shows up in homebrew via these casks:
Copybrew install --cask temurin8
brew install --cask temurin9
And add them to be managed by jenv as usual.
Copyjenv 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
You can check the paths of the versions installed using
/usr/libexec/java_home -V, see How do I check if the Java JDK is installed on Mac?On Mac OS X Mavericks, I found as following:
Built-in JRE default:
/Library/Internet\ Plug-Ins/JavaAppletPlugin.plugin/Contents/HomeJDKs downloaded from Apple:
/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home/JDKs downloaded from Oracle:
/Library/Java/JavaVirtualMachines/jdk1.8.0_11.jdk/Contents/Home
Resources
- Removing Java 8 JDK from Mac
- http://hanxue-it.blogspot.ch/2014/05/installing-java-8-managing-multiple.html
- http://sourabhbajaj.com/mac-setup/index.html
- http://brew.sh
- https://github.com/Homebrew/homebrew/tree/master/share/doc/homebrew#readme
- http://sourabhbajaj.com/mac-setup/Homebrew/README.html
- "brew tap” explained https://github.com/Homebrew/homebrew/blob/master/share/doc/homebrew/brew-tap.md
- “brew versions” explained Homebrew install specific version of formula? and also https://github.com/Homebrew/homebrew-versions
- https://github.com/caskroom/homebrew-cask
- “cask versions”, similar to “brew versions”, see https://github.com/caskroom/homebrew-versions and also https://github.com/caskroom/homebrew-cask/issues/9447
- http://www.jenv.be
- https://github.com/gcuisinier/jenv
The cleanest way to manage multiple java versions on Mac is to use Homebrew.
And within Homebrew, use:
homebrew-caskto install the versions of javajenvto manage the installed versions of java
As seen on http://hanxue-it.blogspot.ch/2014/05/installing-java-8-managing-multiple.html , these are the steps to follow.
- install homebrew
- install homebrew jenv
- install homebrew-cask
- install a specific java version using cask (see "homebrew-cask versions" paragraph below)
- add this version for jenv to manage it
- 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 homebrew/cask-versions tap to homebrew using:
Copybrew tap homebrew/cask-versions
Then you can look at all the versions available by searching for Eclipse temurin, more details here
Copybrew search temurin
Then you can install the version(s) you like, though version 7 no longer shows up in homebrew via these casks:
Copybrew install --cask temurin8
brew install --cask temurin9
And add them to be managed by jenv as usual.
Copyjenv 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
You can check the paths of the versions installed using
/usr/libexec/java_home -V, see How do I check if the Java JDK is installed on Mac?On Mac OS X Mavericks, I found as following:
Built-in JRE default:
/Library/Internet\ Plug-Ins/JavaAppletPlugin.plugin/Contents/HomeJDKs downloaded from Apple:
/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home/JDKs downloaded from Oracle:
/Library/Java/JavaVirtualMachines/jdk1.8.0_11.jdk/Contents/Home
Resources
- Removing Java 8 JDK from Mac
- http://hanxue-it.blogspot.ch/2014/05/installing-java-8-managing-multiple.html
- http://sourabhbajaj.com/mac-setup/index.html
- http://brew.sh
- https://github.com/Homebrew/homebrew/tree/master/share/doc/homebrew#readme
- http://sourabhbajaj.com/mac-setup/Homebrew/README.html
- "brew tap” explained https://github.com/Homebrew/homebrew/blob/master/share/doc/homebrew/brew-tap.md
- “brew versions” explained Homebrew install specific version of formula? and also https://github.com/Homebrew/homebrew-versions
- https://github.com/caskroom/homebrew-cask
- “cask versions”, similar to “brew versions”, see https://github.com/caskroom/homebrew-versions and also https://github.com/caskroom/homebrew-cask/issues/9447
- http://www.jenv.be
- https://github.com/gcuisinier/jenv
Uninstall jdk8, install jdk7, then reinstall jdk8.
My approach to switching between them (in .profile) :
Copyexport JAVA_7_HOME=$(/usr/libexec/java_home -v1.7)
export JAVA_8_HOME=$(/usr/libexec/java_home -v1.8)
export JAVA_9_HOME=$(/usr/libexec/java_home -v9)
export JAVA_20_HOME=$(/usr/libexec/java_home -v20)
alias java7='export JAVA_HOME=$JAVA_7_HOME'
alias java8='export JAVA_HOME=$JAVA_8_HOME'
alias java9='export JAVA_HOME=$JAVA_9_HOME'
alias java20='export JAVA_HOME=$JAVA_20_HOME'
#default java8
export JAVA_HOME=$JAVA_8_HOME
Then you can simply type java7 or java8 in a terminal to switch versions.
(edit: updated to add Dylans improvement for Java 9)
How to choose between multiple JDK's on MacOS?
Getting started with SDKMAN! – Manage Java, Maven, Gradle versions with ease
Switching versions of Java on Mac OSX
How to choose between multiple JDK's on MacOS? : r/java
Videos
On MacOS, you can run /usr/libexec/java_home to get the current JDK MacOS will use...
On my system, it's:
OpenJDK Runtime Environment Zulu16.32+15-CA (build 16.0.2+7)
But, I have multiple JDK's installed:
/usr/libexec/java_home -V
Matching Java Virtual Machines (2):
16.0.2 (arm64) "Azul Systems, Inc." - "Zulu 16.32.15" /Library/Java/JavaVirtualMachines/zulu-16.jdk/Contents/Home
16.0.2 (x86_64) "Oracle Corporation" - "Java SE 16.0.2" /Library/Java/JavaVirtualMachines/jdk-16.0.2.jdk/Contents/Home
Does anyone know how (if I can) switch what MacOS will use by default?
So far, if I delete the current default, it'll switch to the one remaining (I've tried this my moving the current JDK to /tmp). But is there a more elegant way to do this?