Set up Multiple Java Dev Environments for macOS — 2025+ Edition

Setting up a Java development environment can be tricky, especially when you need to manage multiple JDK versions.
While preparing a new machine for work, I realized my old blog post on this topic was outdated.
So, as 2025 comes to a close, I decided to update the tutorial and make it useful for other developers who need to set up their own Java environment.
Prerequisite
Install Homebrew
$ /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
Install JDK
Search for the desired Java version using:
$ brew search jdk
==> Formulae
openjdk openjdk@11 openjdk@17 openjdk@21 openjdk@8 jd mdk cdk
==> Casks
adoptopenjdk jdk-mission-control microsoft-openjdk@25 oracle-jdk@21 semeru-jdk-open@21
gama-jdk microsoft-openjdk oracle-jdk sapmachine-jdk semeru-jdk-open@8
graalvm-jdk microsoft-openjdk@11 oracle-jdk-javadoc semeru-jdk-open
graalvm-jdk@17 microsoft-openjdk@17 oracle-jdk-javadoc@21 semeru-jdk-open@11
graalvm-jdk@21 microsoft-openjdk@21 oracle-jdk@17 semeru-jdk-open@17
In this case, I will use Microsoft OpenJDK versions 21 and 25:
- microsoft-openjdk@21
- microsoft-openjdk (version 25)
Note: if you want to use only a single version, you can just pick one version and then install and close this tutorial
In this tutorial, we’ll install 2 versions of Java as mentioned and demonstrate how to manage them using jenv. We’ll install using these commands:
$ brew install microsoft-openjdk
$ brew install microsoft-openjdk@21
If the installation is successful, you can list the installed path:
$ ls -al /Library/Java/JavaVirtualMachines/
total 0
drwxr-xr-x 4 root wheel 128 Oct 2 16:43 .
drwxr-xr-x 4 root wheel 128 Oct 2 16:31 ..
drwxr-xr-x 3 root wheel 96 Jul 11 04:31 microsoft-21.jdk
drwxr-xr-x 3 root wheel 96 Sep 17 04:48 microsoft-25.jdk
$ tree -L 3 /Library/Java/JavaVirtualMachines/
/Library/Java/JavaVirtualMachines/
├── microsoft-21.jdk
│ └── Contents # (we'll use this path when jenv add)
│ ├── Home
│ ├── Info.plist
│ ├── MacOS
│ └── _CodeSignature
└── microsoft-25.jdk
└── Contents # (we'll use this path when jenv add)
├── Home
├── Info.plist
├── MacOS
└── _CodeSignature
Manage Multiple Java Versions Using jenv
Install jenv
Jenv is a Java version environment like nvm or rbenv, but for Java. We’ll install jenv using Homebrew:
$ brew install jenv
==> Fetching downloads for: jenv
==> Downloading https://ghcr.io/v2/homebrew/core/jenv/manifests/0.5.9
Already downloaded: /Users/ayuth/Library/Caches/Homebrew/downloads/9027b15da7ef5210164c80246e675d8c3bccdf0dcc361f9c37663b81207284cd--jenv-0.5.9.bottle_manifest.json
==> Fetching jenv
==> Downloading https://ghcr.io/v2/homebrew/core/jenv/blobs/sha256:b454f9bfe4726a30422faed10c3fa103050a5dcb0fa39f366691bda9
Already downloaded: /Users/ayuth/Library/Caches/Homebrew/downloads/f37afca1709fc46f03b057d7f238c465a365e87f71f784c7e66c3765c9a96716--jenv--0.5.9.all.bottle.tar.gz
==> Pouring jenv--0.5.9.all.bottle.tar.gz
==> Caveats
To activate jenv, add the following to your shell profile e.g. ~/.profile
or ~/.zshrc:
export PATH="$HOME/.jenv/bin:$PATH"
eval "$(jenv init -)"
==> Summary
🍺 /opt/homebrew/Cellar/jenv/0.5.9: 91 files, 100.9KB
==> Running `brew cleanup jenv`...
Disable this behaviour by setting `HOMEBREW_NO_INSTALL_CLEANUP=1`.
Hide these hints with `HOMEBREW_NO_ENV_HINTS=1` (see `man brew`).
Then put the path to ~/.zshrc using this command:
$ echo 'export PATH="$HOME/.jenv/bin:$PATH"' >> ~/.zshrc
$ echo 'eval "$(jenv init -)"' >> ~/.zshrc
Add Java paths to jenv using this command:
$ jenv add /Library/Java/JavaVirtualMachines/{YOUR_JDK_VERSION}/Contents/Home
Replace <YOUR_JDK_VERSION> using the output above. For this tutorial would be this:
$ jenv add /Library/Java/JavaVirtualMachines/microsoft-21.jdk/Contents/Home
openjdk64-21.0.8 added
21.0.8 added
21.0 added
21 added
$ jenv add /Library/Java/JavaVirtualMachines/microsoft-25.jdk/Contents/Home
openjdk64-25 added
25 added
Then check the versions in the jenv
$ jenv versions
* system (set by /Users/user/.jenv/version)
21
21.0
21.0.8
25
openjdk64-21.0.8
openjdk64-25
Then let’s try to switch between jenv versions:
$ jenv shell 25
$ java --version
openjdk 25 2025-09-16 LTS
OpenJDK Runtime Environment Microsoft-12398179 (build 25+36-LTS)
OpenJDK 64-Bit Server VM Microsoft-12398179 (build 25+36-LTS, mixed mode, sharing)
$ jenv shell 21
$ java --version
openjdk 21.0.8 2025-07-15 LTS
OpenJDK Runtime Environment Microsoft-11933201 (build 21.0.8+9-LTS)
OpenJDK 64-Bit Server VM Microsoft-11933201 (build 21.0.8+9-LTS, mixed mode, sharing)
Essential JAVA_ENV Paths Setup
For some applications or CLI, it requires the $JAVA_HOME path. Luckily, we have the plugin called export
$ jenv enable-plugin export
You may restart your session to activate jenv export plugin
export plugin activated
After restarting your shell session,
$ echo $JAVA_HOME
/Users/user/.jenv/versions/21
Managing Java Versions
You can configure the Java version at three different levels: global, local, or shell.
To set a global Java version:
$ jenv global 25
To set a local version for a specific project or directory:
$ jenv local 25
To set a temporary version for the current shell session:
$ jenv shell 17
To verify that the current installation is fine, you can call
$ jenv doctor
jenv doctor
[OK] JAVA_HOME variable probably set by jenv PROMPT
[OK] Java binaries in path are jenv shims
[OK] Jenv is correctly loaded
Install Other Useful Binaries
You could install the gradle and maven using homebrew:
# gradle
$ brew install gradle
# maven
$ brew install maven

That is, thank you for reading, and I hope this tutorial comes to your mind when you need to set up a Java development environment.
References:
Set up Multiple Java Dev Environments for macOS — 2025+ Edition was originally published in Ayuth’s Story on Medium, where people are continuing the conversation by highlighting and responding to this story.