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 many JDK on macOS using Homebrew ad openjdk
February 20, 2023 - We are all done. Just type java-11 or java-17 on your Terminal or iTerm whenever you want to change the java versions. ... For all those who just want the steps, not any explanation, here are the quick steps.
Discussions

macos - How to install specific Java version using Homebrew? - Stack Overflow
Error: homebrew/cask-versions was deprecated. This tap is now empty and all its contents were either deleted or migrated. 2025-07-28T14:01:07.803Z+00:00 ... Then if you want to install specific version run following command .. ... sudo ln -sfn /usr/local/opt/openjdk@11/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk-11.jdk · change ... More on stackoverflow.com
🌐 stackoverflow.com
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
How to set or change the default Java (JDK) version on macOS? - Stack Overflow
I would make a cli tool similar to nvm for switching Java versions, but the acronym jvm already means something else :) 2018-09-22T18:48:10.163Z+00:00 ... I get this error when sourcing: /Users/me/.zshrc:8: permission denied: /Library/Java/JavaVirtualMachines/openjdk-12.jdk/Contents/Home 2019-04-04T22:28:32.053Z+00:00 ... @cosbor11 for .zshrc use export JAVA_HOME=$(/usr/libexec/java_home -v 12) 2019-08-22T12:12:54.087Z+00:00 ... Save this answer. ... Show activity on this post. Due to multiple Homebrew... More on stackoverflow.com
🌐 stackoverflow.com
Shall I use Homebrew or SDKMAN to install older versions of Java (e.g. Java 8 or 11)?
I've been using Sdkman for a couple of years. It's a really decent tool. I would recommend it. More on reddit.com
🌐 r/java
35
11
July 6, 2020
🌐
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.
🌐
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 - Step-by-Step Guide: Installing and Switching Java Versions on Mac OSX To install Java on macOS and allow for easy switching between different versions, you can use a version manager like jenv. Here's …
🌐
GitHub
gist.github.com › gwpantazes › 50810d5635fc2e053ad117b39b597a14
How to install different JDK versions on MacOS with Homebrew · GitHub
$ brew tap homebrew/cask-versions $ brew cask install homebrew/cask-versions/adoptopenjdk8 ... Thanks @envs, I've incorporated your changes into a rewrite. Honestly, using homebrew to install Java (especially OpenJDK) has gotten quite a bit ...
🌐
Snyk
snyk.io › blog › installing-and-managing-java-on-macos
Installing and managing Java on macOS | Snyk
October 12, 2023 - Run the following command in your terminal, replacing 11 with your desired Java version: ... Homebrew may not set up the JAVA_HOME environment variable automatically, so you should add the following lines to your shell profile file (.bash_profile, .zshrc, etc.):
🌐
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 - Now, to switch between the Java versions, enter an alias java8 in your terminal. Execute java -version to verify that you are now using the correct Java version. Alias **only** changes the Java version in the used terminal instance
Find elsewhere
🌐
DevQA
devqa.io › switch-between-different-java-versions-mac
How to Switch Between Different Java Versions on Mac
July 4, 2023 - 1 - Install jenv using Homebrew by running the following command in Terminal: ... 2 - Once the installation is complete, you need to initialize jenv. Run the following command to add jenv to your shell: ... If you’re using a different shell (such as Zsh), replace ~/.bash_profile with the appropriate configuration file (e.g., ~/.zshrc). 3 - Restart your Terminal or run the following command to apply the changes: ... 4 - Now, you can install different versions of Java using Homebrew.
🌐
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
Now you can change the java version on the terminal using the respective alias: $ j17 openjdk version "17.0.1" 2021-10-19 OpenJDK Runtime Environment Homebrew (build 17.0.1+0) OpenJDK 64-Bit Server VM Homebrew (build 17.0.1+0, mixed mode, sharing) $ j11 openjdk version "11.0.12" 2021-07-20 OpenJDK Runtime Environment Homebrew (build 11.0.12+0) OpenJDK 64-Bit Server VM Homebrew (build 11.0.12+0, mixed mode) $ j1.8 openjdk version "1.8.0_312" OpenJDK Runtime Environment (build 1.8.0_312-bre_2021_10_20_23_15-b00) OpenJDK 64-Bit Server VM (build 25.312-b00, mixed mode)
🌐
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 I want to reverse this and go back to openjdk 11, I can use this unlink command and see this: % sudo unlink /Library/Java/JavaVirtualMachines/openjdk-21.jdk % java --version openjdk 11.0.20.1 2023-08-24 OpenJDK Runtime Environment Homebrew (build 11.0.20.1+0) OpenJDK 64-Bit Server VM Homebrew (build 11.0.20.1+0, mixed mode) % ls /library/Java/JavaVirtualMachines jdk1.8.0_261.jdk openjdk-11.jdk berniemichalik@Bernies-MacBook-Air-4 ~ %
🌐
GitHub
gist.github.com › gramcha › 81dcec3f1e4ce8cffd7f248d3e2a42a7
Managing multiple Java versions in MacOS · GitHub
PATH : /usr/local/Cellar/jenv/0.5.2/libexec/libexec:/Users/gramcha/.jenv/shims:/Users/gramcha/.jenv/shims:/Users/gramcha/.jenv/bin:/Users/gramcha/.jenv/bin:/Users/gramcha/chromedriver:/opt/local/bin:/opt/local/sbin:/Users/gramcha/.jenv/shims:/Users/gramcha/.jenv/bin:/Users/gramcha/.jenv/bin:/Users/gramcha/chromedriver:/opt/local/bin:/opt/local/sbin:/Users/gramcha/.jenv/shims:/Users/gramcha/.jenv/bin:/Users/gramcha/.jenv/shims:/Users/gramcha/.jenv/bin:/Users/gramcha/chromedriver:/opt/local/bin:/opt/local/sbin:/Users/gramcha/.nvm/versions/node/v10.17.0/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin [OK] Jenv is correctly loaded · No need to worry about error message as long as Jenv is correctly loaded is printed. ... Updating Homebrew...
🌐
Reddit
reddit.com › r/java › how to choose between multiple jdk's on macos?
r/java on Reddit: How to choose between multiple JDK's on MacOS?
August 29, 2021 -

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?

🌐
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.
🌐
MungingData
mungingdata.com › java › jenv-multiple-versions-java
Running Multiple Versions of Java on MacOS with jenv - MungingData
Here's the latest command to install ... caskroom/versions/adoptopenjdk8 also used to work, but now returns Error: caskroom/versions was moved. Tap homebrew/cask-versions instead....
Top answer
1 of 16
2562

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

CopyMatching 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:

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

or you can specify just the major version, like:

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

Now when you run java -version you will see:

Copyjava 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):

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

For Fish (as stated by ormurin)

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

Updating the .zshrc file should work:

Copynano ~/.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

Copysource ~/.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.

🌐
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.
🌐
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 - $ jenv global 11 $ echo $JAVA_HOME /Users/mrn/.jenv/versions/11 $ java -version openjdk version "11.0.29" 2025-10-21 OpenJDK Runtime Environment Homebrew (build 11.0.29+0) OpenJDK 64-Bit Server VM Homebrew (build 11.0.29+0, mixed mode) Changed my mind, I want Java 21: $ jenv global 21 $ echo $JAVA_HOME /Users/mrn/.jenv/versions/21 $ java -version openjdk version "21.0.9" 2025-10-21 OpenJDK Runtime Environment Homebrew (build 21.0.9) OpenJDK 64-Bit Server VM Homebrew (build 21.0.9, mixed mode, sharing) All without having to restart the shell!
🌐
Khuong Dev
dev.ngockhuong.com › posts › change-the-default-java-jdk-version-on-macos
Change the default Java (JDK) version on macOS | Khuong Dev
February 23, 2026 - https://dev.to/rithvik78/change-the-default-java-version-on-macos-3jee · https://github.com/AdoptOpenJDK/homebrew-openjdk#adoptopenjdk---homebrew-tap · Programming Languages, Java · java jdk macos · This post is licensed under CC BY 4.0 by the author. Share · Jekyll Chirpy Text and Typography ·