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)

🌐
Mac Install Guide
mac.install.guide › java › version-managers
Java Version Managers · Mac Install Guide · 2026
Here are the most popular and recommended Java version managers. SDKMAN – JVM-focused (Java, Kotlin, Scala), installs JDKs plus Maven, Gradle, Spring Boot CLI · mise – Polyglot (Java + Node + Python + Ruby), fastest performance, unified config, automatic JAVA_HOME · jEnv – Homebrew-centric workflow, lightweight switching for Homebrew-installed JDKs · Manual method – Simple needs (1–2 JDKs), no tools required, uses built-in macOS utility
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
Getting started with SDKMAN! – Manage Java, Maven, Gradle versions with ease
I love sdkman!!! sdk install java 23.0.2-amzn sdk install maven sdk install gradle so easy!!! More on reddit.com
🌐 r/java
39
85
April 20, 2025
Switching versions of Java on Mac OSX
Not standard, but easier, try using sdkman. More on reddit.com
🌐 r/javahelp
10
1
January 7, 2023
How to choose between multiple JDK's on MacOS? : r/java
🌐 r/java
🌐
SDKMAN!
sdkman.io
Home | SDKMAN! the Software Development Kit Manager
Install Software Development Kits for the JVM such as Java, Scala, Kotlin and Groovy. Ant, Gradle, Grails, Maven, SBT, Spark, Spring Boot, Vert.x and many others also supported. Written in Rust and bash and only requires curl, zip, and unzip dependencies to be present on your system. Even works with ZSH too. Operates seamlessly across various UNIX-based platforms, including macOS, Linux, and Windows Subsystem for Linux (WSL) on Windows.
🌐
Faun
faun.pub › simplify-java-version-management-on-macos-a-guide-to-sdkman-and-jabba-8f8d563b6c56
Simplify Java Version Management on macOS: A Guide to SDKMAN! and Jabba
October 20, 2024 - Lightweight: Jabba is a lightweight version manager focused solely on managing Java versions, making it a simple and efficient solution for developers who only need to manage Java environments. Easy Installation: Jabba can be installed via Homebrew, a popular package manager for macOS, simplifying the installation process for users familiar with Homebrew.
🌐
GitHub
github.com › jenv › jenv
GitHub - jenv/jenv: Manage your Java environment · GitHub
With macOS OpenJDK 21.0.2 installed, ... Your JVM directory may vary! Observe now that this version of Java is added to your jenv versions command:...
Starred by 6.6K users
Forked by 398 users
Languages   Shell 99.0% | Dockerfile 1.0%
🌐
GitHub
gist.github.com › gramcha › 81dcec3f1e4ce8cffd7f248d3e2a42a7
Managing multiple Java versions in MacOS · GitHub
Managing multiple Java versions in MacOS · Raw · having-multiple-jdk-macos.md · We need to install a tool called jenv - Java version manager which is similar to nvm(nodeJs version manager). brew install jenv · Export the jenv path to ...
🌐
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 …
Find elsewhere
🌐
Snyk
snyk.io › blog › installing-and-managing-java-on-macos
Installing and managing Java on macOS | Snyk
October 12, 2023 - Finally, we can use SDKMAN! to easily switch between Java versions. Running sdk use instructs SDKMAN! to set the active Java version to 19.0.2: ... Now that we’ve reviewed several methods for installing and managing Java on macOS, let's review the answers to some of the most common questions about the process.
🌐
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
🌐
DEV Community
dev.to › blaytenshi › installing-multiple-java-on-macos-managed-by-jenv-l6i
Installing (multiple) Java on MacOS managed by jEnv - DEV Community
October 7, 2024 - We'll create symlinks to versions .../libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk-21.jdk · jenv is a Java installation version manager......
🌐
javaspring
javaspring.net › blog › version-java-mac
Java Version Management on Mac: A Comprehensive Guide — javaspring.net
In this blog, we'll explore the fundamental concepts of Java version management on a Mac, how to use different methods for version management, common practices, and best practices to make your Java development experience smooth.
🌐
Medium
medium.com › @annurahar › manage-various-java-versions-on-mac-osx-e6aee82c882c
Manage various Java versions on Mac OSX | by Annu Rahar | Medium
September 16, 2021 - Manage various Java versions on Mac OSX There are few options to do the installation as well as manage JDK switching. Installation can be done by Homebrew, SDKMAN, Jabba, or a manual install …
🌐
GitHub
gist.github.com › gwpantazes › 50810d5635fc2e053ad117b39b597a14
How to install different JDK versions on MacOS with Homebrew · GitHub
It has a Java plugin which handles downloading/installing and local/shell/global environment (i.e. the roles of Homebrew and jenv respectively). It also has a standard interface for all other languages it supports (which are many: python, ruby, nodejs, etc.), so it's a nice cohesive experience overall. I recommend trying out asdf if you need to do tool version management and switch between multiple versions of things.
🌐
Mac Install Guide
mac.install.guide › mise › mise-java-mac
Java with Mise Version Manager · Mac Install Guide · 2026
March 9, 2026 - Mise is multi-language version manager. Manage Java versions on Mac with Mise instead of SDKMAN. Install, switch distributions, configure JAVA_HOME, and manage build tools.
🌐
Medium
blog.bigoodyssey.com › how-to-manage-multiple-java-version-in-macos-e5421345f6d0
How to Manage Multiple Java Versions in MacOS (Updated 2023 + macOS Ventura) | by Chamika Kasun | Medium
February 7, 2023 - I have been using multiple versions of Java with a Version Manager on my Mac for a while, whenever I need to switch between different projects which use different versions of Java this feature becomes handier so I thought of sharing with you how you can use a Java Version Manager-jEnv in your daily work in order to switch between multiple Java versions.
🌐
MungingData
mungingdata.com › java › jenv-multiple-versions-java
Running Multiple Versions of Java on MacOS with jenv - MungingData
Switching manually is possible, but who wants to waste mental energy thinking about Java versions every time they switch a project? jenv will help you manage Java on your Mac, even if you only need to use a single version.
🌐
GitHub
github.com › shyiko › jabba
GitHub - shyiko/jabba: (cross-platform) Java Version Manager · GitHub
(cross-platform) Java Version Manager. Contribute to shyiko/jabba development by creating an account on GitHub.
Starred by 3.4K users
Forked by 222 users
Languages   Go 83.8% | Shell 10.1% | PowerShell 3.6% | Makefile 2.5%
🌐
Mac Install Guide
mac.install.guide › java › sdkman
Install SDKMAN for Java on Mac · Mac Install Guide · 2026
The Java version manager SDKMAN, or Software Development Kit Manager, is a command-line tool that installs, manages, and switches among multiple Java versions on macOS.
🌐
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?