Java
Mac
Versions
Installation
Software Configuration

List all Java versions installed on a Mac

Codemia Knowledge Hub ·

Run /usr/libexec/java_home -V in Terminal. This built-in macOS utility lists every JDK it finds under /Library/Java/JavaVirtualMachines/, with the version, architecture, vendor and install path of each.

bash
/usr/libexec/java_home -V

Sample output:

 
1Matching Java Virtual Machines (3):
2    21.0.2 (arm64) "Eclipse Adoptium" - "OpenJDK 21.0.2" /Library/Java/JavaVirtualMachines/temurin-21.jdk/Contents/Home
3    17.0.9 (arm64) "Eclipse Adoptium" - "OpenJDK 17.0.9" /Library/Java/JavaVirtualMachines/temurin-17.jdk/Contents/Home
4    11.0.21 (arm64) "Eclipse Adoptium" - "OpenJDK 11.0.21" /Library/Java/JavaVirtualMachines/temurin-11.jdk/Contents/Home

Multiple versions are normal: a legacy service might need Java 11 while a newer one targets Java 21, and Maven and Gradle respect JAVA_HOME. Homebrew casks and manual .pkg installers put JDKs in /Library/Java/JavaVirtualMachines/, so versions pile up there (SDKMAN! uses its own folder, see below).

Checking the active Java version

java_home -V shows what is installed. To see which version the current shell uses:

bash
java -version

This reports the version of the java binary on your PATH. If JAVA_HOME is set, most build tools use that instead.

To see which binary the shell resolves:

bash
which java

On modern macOS this is often /usr/bin/java, a shim that delegates to the JDK selected by java_home.

Switching between installed versions

Setting JAVA_HOME

java_home returns the path for a given version, which you assign to JAVA_HOME:

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

Add it to ~/.zshrc (or ~/.bash_profile on older macOS) to make it persistent. To switch, change the number and reload your shell:

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

A shell function for quick switching

bash
1# Add to ~/.zshrc
2jdk() {
3    export JAVA_HOME=$(/usr/libexec/java_home -v "$1")
4    echo "JAVA_HOME set to $JAVA_HOME"
5    java -version
6}

Usage:

bash
jdk 17
jdk 21

SDKMAN!

SDKMAN! installs and switches versions in one tool:

bash
1# Install SDKMAN!
2curl -s "https://get.sdkman.io" | bash
3source "$HOME/.sdkman/bin/sdkman-init.sh"
4
5# List available versions
6sdk list java
7
8# Install a specific version
9sdk install java 21.0.2-tem
10
11# Switch for the current session
12sdk use java 17.0.9-tem
13
14# Set as default
15sdk default java 21.0.2-tem

SDKMAN! installs JDKs to ~/.sdkman/candidates/java/, not the system directory, so java_home -V does not list them. Use sdk list java for those.

Which command shows what

MethodCommandWhat it showsScope
java_home -V/usr/libexec/java_home -VAll system-installed JDKsSystem-wide
java -versionjava -versionActive JDK for current shellCurrent session
which javawhich javaPath to the resolved java binaryCurrent session
SDKMAN!sdk list javaSDKMAN!-managed JDKs (installed and available)SDKMAN!-managed
Homebrewbrew list --versions openjdkHomebrew-installed JDK packagesHomebrew-managed

Where JDKs are installed

Standard macOS JDK installers use:

 
/Library/Java/JavaVirtualMachines/

List the directory directly:

bash
ls /Library/Java/JavaVirtualMachines/

Each JDK has its own directory, usually named by vendor and version:

 
temurin-17.jdk
temurin-21.jdk
zulu-11.jdk

The JAVA_HOME path is one level deeper:

 
/Library/Java/JavaVirtualMachines/temurin-21.jdk/Contents/Home

Removing old Java versions

Delete the JDK's directory:

bash
sudo rm -rf /Library/Java/JavaVirtualMachines/temurin-11.jdk

If it came from Homebrew:

bash
brew uninstall --cask temurin@11

If it came from SDKMAN!:

bash
sdk uninstall java 11.0.21-tem

Run /usr/libexec/java_home -V again to confirm it is gone.

Java version used by Maven and Gradle

bash
1# Maven
2mvn -version
3
4# Gradle
5gradle --version
6
7# Output includes the JVM version and JAVA_HOME path

If this does not match java -version, the tool probably has its own JAVA_HOME override in its configuration or wrapper script.

Apple Silicon vs Intel JDKs

On Apple Silicon, the architecture column shows arm64. Rosetta-translated Intel JDKs show x86_64. Both can coexist, but mixing them in one build can break native libraries.

Filter by architecture:

bash
/usr/libexec/java_home -V --arch arm64
/usr/libexec/java_home -V --arch x86_64

Why the version you see is not the one in use

  • IDEs keep their own JDK setting. IntelliJ IDEA and others keep a project JDK setting independent of JAVA_HOME, so check the IDE's project settings separately.
  • The shell was not reloaded. After editing ~/.zshrc, run source ~/.zshrc or open a new terminal.
  • Several package managers. Mixing Homebrew, SDKMAN! and manual .pkg installs makes it unclear what lives where. Pick one.
  • java_home only scans /Library/Java/JavaVirtualMachines/. JDKs elsewhere, such as ~/.sdkman/, are invisible to it. If it lists fewer versions than you expect, check other tools.

Course
Intermediate
27 lessons
14 hours
OOD Fundamentals

Master object-oriented design from first principles, SOLID, design patterns, and classic interview problems with hands-on coding.

View the course
Data Structures & Algorithms practice on Codemia

Step through 300+ coding interview problems with animated visualisers that show the data structure changing as the code runs. The Blind 75 are free.

Practice algorithms