The cleanest way to manage multiple java versions on Mac is to use Homebrew.

And within Homebrew, use:

  • homebrew-cask to install the versions of java
  • jenv to 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.

  1. install homebrew
  2. install homebrew jenv
  3. install homebrew-cask
  4. install a specific java version using cask (see "homebrew-cask versions" paragraph below)
  5. add this version for jenv to manage it
  6. check the version is correctly managed by jenv
  7. 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:

  1. Built-in JRE default: /Library/Internet\ Plug-Ins/JavaAppletPlugin.plugin/Contents/Home

  2. JDKs downloaded from Apple: /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home/

  3. 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
Answer from Adri w Ukraine on Stack Overflow
Top answer
1 of 16
649

The cleanest way to manage multiple java versions on Mac is to use Homebrew.

And within Homebrew, use:

  • homebrew-cask to install the versions of java
  • jenv to 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.

  1. install homebrew
  2. install homebrew jenv
  3. install homebrew-cask
  4. install a specific java version using cask (see "homebrew-cask versions" paragraph below)
  5. add this version for jenv to manage it
  6. check the version is correctly managed by jenv
  7. 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:

  1. Built-in JRE default: /Library/Internet\ Plug-Ins/JavaAppletPlugin.plugin/Contents/Home

  2. JDKs downloaded from Apple: /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home/

  3. 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
2 of 16
445

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)

🌐
Medium
medium.com › @manvendrapsingh › installing-many-jdk-versions-on-macos-dfc177bc8c2b
Installing & switching between multiple JDK on macOS | by Manvendra P Singh | Medium
February 20, 2023 - Lets use HomeBrew, openjdk and zshrc to install and manage different java / JDK versions on MacOS / OsX
Discussions

How to choose between multiple JDK's on MacOS?
I have used sdkman - you can use it to manage your sdks like java, Scala, groovy More on reddit.com
🌐 r/java
30
22
August 29, 2021
Easily switch between java versions with SDKMAN! and 'j'
Gradle and toolchain is my personal best solution. So you don't need to configure your environment on each project if you have to manage different java version. And in addition it works very well together with sdkman. More on reddit.com
🌐 r/java
41
20
December 30, 2022
Top answer
1 of 16
2562

First run /usr/libexec/java_home -V which will output something like the following:

Matching Java Virtual Machines (3):
1.8.0_05, x86_64:   "Java SE 8" /Library/Java/JavaVirtualMachines/jdk1.8.0_05.jdk/Contents/Home
1.6.0_65-b14-462, x86_64:   "Java SE 6" /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home
1.6.0_65-b14-462, i386: "Java SE 6" /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home

/Library/Java/JavaVirtualMachines/jdk1.8.0_05.jdk/Contents/Home

Pick the version you want to be the default (1.6.0_65-b14-462 for arguments sake) then:

export JAVA_HOME=`/usr/libexec/java_home -v 1.6.0_65-b14-462`

or you can specify just the major version, like:

export JAVA_HOME=`/usr/libexec/java_home -v 1.8`

Now when you run java -version you will see:

java version "1.6.0_65"
Java(TM) SE Runtime Environment (build 1.6.0_65-b14-462-11M4609)
Java HotSpot(TM) 64-Bit Server VM (build 20.65-b04-462, mixed mode)

Add the export JAVA_HOME… line to your shell’s init file.

For Bash (as stated by antonyh):

export JAVA_HOME=$(/usr/libexec/java_home -v 1.8)

For Fish (as stated by ormurin)

set -x JAVA_HOME (/usr/libexec/java_home -d64 -v1.8)

Updating the .zshrc file should work:

nano ~/.zshrc

export JAVA_HOME=$(/usr/libexec/java_home -v 1.8.0)

Press CTRL+X to exit the editor Press Y to save your changes

source ~/.zshrc
echo $JAVA_HOME
java -version
2 of 16
608

This answer is an attempt to address: how to control java version system-wide (not just in currently running shell) when several versions of JDK are installed for development purposes on macOS El Capitan or newer (Sierra, High Sierra, Mojave). As far as I can tell, none of the current answers do that (*).

As a developer, I use several JDKs, and I want to switch from one to the other easily. Usually I have the latest stable one for general use, and others for tests. But I don't want the system (e.g. when I start my IDE) to use the latest "early access" version I have for now. I want to control system's default, and that should be latest stable.

The following approach works with Java 7 to 12 at least (early access at the time of this writing), with Oracle JDK or OpenJDK (including builds by AdoptOpenJDK produced after mid-October 2018).

Solution without 3rd party tools:

  • leave all JDKs at their default location, under /Library/Java/JavaVirtualMachines. The system will pick the highest version by default.
  • To exclude a JDK from being picked by default, rename its Contents/Info.plist to Info.plist.disabled. That JDK can still be used when $JAVA_HOME points to it, or explicitly referenced in a script or configuration. It will simply be ignored by system's java command.

System launcher will use the JDK with highest version among those that have an Info.plist file.

When working in a shell with alternate JDK, pick your method among existing answers (jenv, or custom aliases/scripts around /usr/libexec/java_home, etc).


Details of investigation in this gist.


(*) Current answers are either obsolete (no longer valid for macOS El Capitan or Sierra), or only address a single JDK, or do not address the system-wide aspect. Many explain how to change $JAVA_HOME, but this only affects the current shell and what is launched from there. It won't affect an application started from OS launcher (unless you change the right file and logout/login, which is tedious). Same for jenv, it's cool and all, but as far as I can tell it merely changes environment variables, so it has the same limitation.

🌐
GitHub
gist.github.com › gwpantazes › 50810d5635fc2e053ad117b39b597a14
How to install different JDK versions on MacOS with Homebrew · GitHub
I recommend jEnv for switching between multiple Java environments on MacOS. I think it's generally wise to have homebrew/cask and homebrew/cask-versions tapped. They are practically core. SDKMAN is a SDK downloader and manager that can be a viable alternative to Homebrew for installing JDKs and even managing them. ... There has since been a change to the steps. I believe the recent ones I've come across are: $ brew tap homebrew/cask-versions $ brew cask install homebrew/cask-versions/adoptopenjdk8
🌐
Medium
medium.com › @haroldfinch01 › step-by-step-guide-installing-and-switching-java-versions-on-mac-osx-f3896b9872f4
Step-by-Step Guide: Installing and Switching Java Versions on Mac OSX | by Harold Finch | Medium
May 21, 2024 - jenv is a Java environment manager that makes it easy to switch between different versions of Java. Install jenv · brew install jenv · Add jenv to your shell · Add the following lines to your shell startup file (~/.bash_profile, ~/.zshrc, etc.): export PATH="$HOME/.jenv/bin:$PATH" eval "$(jenv init -)" Then, source the file to apply the changes: source ~/.zshrc # or ~/.bash_profile, ~/.bashrc, etc.
🌐
DevQA
devqa.io › switch-between-different-java-versions-mac
How to Switch Between Different Java Versions on Mac
July 4, 2023 - 3 - Restart your Terminal or run the following command to apply the changes: $ source ~/.bash_profile · 4 - Now, you can install different versions of Java using Homebrew. For example, to install AdoptOpenJDK version 11, run: $ brew install --cask adoptopenjdk@11 · You can install multiple versions of Java using this command. Related: How to use brew to install Java on Mac ·
🌐
Lotharschulz
lotharschulz.info › 2021 › 11 › 30 › how-to-switch-between-java-lts-versions-8-11-and-17-on-mac
How to switch between Java LTS versions 8, 11 and 17 on Mac – Lothar Schulz
# version 17 brew install openjdk@17 sudo ln -sfn /usr/local/opt/openjdk@17/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk-17.jdk # version 11 brew install openjdk@11 sudo ln -sfn /usr/local/opt/openjdk@11/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk-11.jdk # version 8 brew install openjdk@8 sudo ln -sfn /usr/local/opt/openjdk@8/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk-8.jdk
Find elsewhere
🌐
Mac Install Guide
mac.install.guide › java › brew-cask
Brew Install Java - Easy Cask Method · 2026
Many older tutorials instruct you to run brew tap homebrew/cask-versions before installing versioned Java casks. This tap is deprecated. Modern Homebrew uses the @ syntax directly: ... You now have Java installed and ready to use. If you need to switch between multiple Java versions for different projects, see Java Version Managers to learn about jEnv, SDKMAN, and other tools for switching Java versions. My mac.install.guide is a trusted source of installation guides for professional developers.
🌐
Smart People I Know
smartpeopleiknow.com › 2023 › 10 › 23 › how-to-work-with-java-on-your-mac-including-having-multiple-versions-of-java-on-your-mac
How to work with Java on your Mac, including having multiple versions of Java on your Mac – Smart People I Know
October 23, 2023 - If you want to install an older version, you can do something like this: $ brew install java11 · If you’ve done this a few times, you may have a few different version of Java installed liked me, and if you enter the following command it may look something like this: % ls /usr/local/opt | grep openjdk openjdk openjdk@11 openjdk@18 openjdk@19 openjdk@20 openjdk@21 % As you can see, I have a few different versions installed.
🌐
Snyk
snyk.io › blog › installing-and-managing-java-on-macos
Installing and managing Java on macOS | Snyk
October 12, 2023 - Running sdk use instructs SDKMAN! ... or employ a versatile tool like SDKMAN!. To set or change the Java path, edit the environment variable, JAVA_HOME....
🌐
notiz
notiz.dev › blog › how-to-manage-multiple-java-versions-on-mac
How to manage multiple Java JDK versions on macOS X
April 16, 2020 - To install the Java JDKs from AdoptOpenJDK: # install from third party repository brew tap adoptopenjdk/openjdk brew cask install adoptopenjdk<version> # Java 8 brew cask install adoptopenjdk8 # Java 9 brew cask install adoptopenjdk9 # Java ...
🌐
Lotharschulz
lotharschulz.info › 2019 › 08 › 21 › mac-change-default-java-version
Change Java version on Mac – Lothar Schulz
August 21, 2019 - Change default java version on Mac · $ brew cask install adoptopenjdk/openjdk/adoptopenjdk8 # which java versions installed $ /usr/libexec/java_home -V Matching Java Virtual Machines (2): 11.0.2, x86_64: "OpenJDK 11.0.2" /Library/.../openjdk-11.0.2.jdk/Contents/Home 1.8.0_222, x86_64:"AdoptOpenJDK ...
🌐
Medium
medium.com › miro-engineering › how-to-switch-between-java-lts-versions-8-11-and-17-on-mac-cb6717d1272
How to switch between Java LTS versions 8, 11, and 17 on Mac | by Lothar Schulz | Miro Engineering | Medium
November 25, 2021 - # version 17 brew install openjdk@17 sudo ln -sfn /usr/local/opt/openjdk@17/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk-17.jdk# version 11 brew install openjdk@11 sudo ln -sfn /usr/local/opt/openjdk@11/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk-11.jdk# version 8 brew install openjdk@8 sudo ln -sfn /usr/local/opt/openjdk@8/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk-8.jdk
🌐
Davidsimpson
davidsimpson.me › 2015 › 08 › 12 › switching-java-versions-easily-on-a-mac
Switching Java versions easily on a Mac - David Simpson
I do a lot of development using Java 7 and recently needed to start using Java 8. The quickest way I know to update to the latest Java uses homebrew: brew tap caskroom/cask brew install brew-cask brew cask install java I now need an easy way to switch back and forth between Java 7 & 8. Adding this to your ~/.bash_profile or ~/.profile does the trick: function setjdk() { if [ $# -ne 0 ]; then removeFromPath '/System/Library/Frameworks/JavaVM.framework/Home/bin' if [ -n "${JAVA_HOME+x}" ]; then removeFromPath $JAVA_HOME fi export JAVA_HOME=`/usr/libexec/java_home -v $@` export PATH=$JAVA_HOME/bin:$PATH fi } function removeFromPath() { export PATH=$(echo $PATH | sed -E -e "s;:$1;;" -e "s;$1:?;;") } # set your default version setjdk 1.7 – Source.
🌐
DevQA
devqa.io › brew-install-java
How to Use Brew to Install Java on Mac
In this article we show how to install Java on Mac using Homebrew, and how to allow to switch between different versions such as Java8, Java11, Java13 and latest Java version. Before we start, make sure you have Homebrew installed on your Mac. If not, you can install it via: $ ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" If you already have brew installed, make sure you have the latest version by running the following command in a terminal
🌐
GitHub
gist.github.com › tinkerware › 8d92524d78f958f3d821b127393a96a1
Maintaining Java Installs on macOS Using Homebrew Cask · GitHub
############### # Java Switcher ############### alias j8="export JAVA_HOME=`/usr/libexec/java_home -v 1.8`; java -version" alias j10="export JAVA_HOME=`/usr/libexec/java_home -v 10`; java -version" alias j11="export JAVA_HOME=`/usr/libexec/java_home -v 11`; java -version" # Set java 8 as default export JAVA_HOME=`/usr/libexec/java_home -v 1.8` ... brew tap adoptopenjdk/openjdk brew cask install adoptopenjdk8 brew cask install adoptopenjdk9 brew cask install adoptopenjdk10 brew cask install adoptopenjdk11 ... Obviously change for your version but the typical methods of finding the path proved difficult so I hope this helps others.
🌐
Mr N
bigsoft.co.uk › blog › 2025 › 11 › 07 › installing-all-the-javas-on-a-mac-and-switching-between-them
Installing all the Javas on a Mac and switching between them
November 7, 2025 - brew install openjdk@8 brew install openjdk@11 brew install openjdk@17 brew install openjdk@21 brew install openjdk@25 ... After the install has completed add this to your ~/.bash_profile and restart the shell. export PATH="$HOME/.jenv/bin:$PATH" eval "$(jenv init -)" If you'd like JAVA_HOME ...
🌐
javathinking
javathinking.com › blog › what-is-the-best-way-to-update-java-version-on-mac-computer
How to Update Java Version on Mac: Best Methods (Brew, Web, & Alternatives) — javathinking.com
(For Apple Silicon Macs, replace /usr/local with /opt/homebrew.) If you have multiple Java versions installed (e.g., Java 11 and 17), use brew link to switch: