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.
Sample output:
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:
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:
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:
Add it to ~/.zshrc (or ~/.bash_profile on older macOS) to make it persistent. To switch, change the number and reload your shell:
A shell function for quick switching
Usage:
SDKMAN!
SDKMAN! installs and switches versions in one tool:
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
| Method | Command | What it shows | Scope |
java_home -V | /usr/libexec/java_home -V | All system-installed JDKs | System-wide |
java -version | java -version | Active JDK for current shell | Current session |
which java | which java | Path to the resolved java binary | Current session |
| SDKMAN! | sdk list java | SDKMAN!-managed JDKs (installed and available) | SDKMAN!-managed |
| Homebrew | brew list --versions openjdk | Homebrew-installed JDK packages | Homebrew-managed |
Where JDKs are installed
Standard macOS JDK installers use:
List the directory directly:
Each JDK has its own directory, usually named by vendor and version:
The JAVA_HOME path is one level deeper:
Removing old Java versions
Delete the JDK's directory:
If it came from Homebrew:
If it came from SDKMAN!:
Run /usr/libexec/java_home -V again to confirm it is gone.
Java version used by Maven and Gradle
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:
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, runsource ~/.zshrcor open a new terminal. - Several package managers. Mixing Homebrew, SDKMAN! and manual
.pkginstalls makes it unclear what lives where. Pick one. java_homeonly scans/Library/Java/JavaVirtualMachines/. JDKs elsewhere, such as~/.sdkman/, are invisible to it. If it lists fewer versions than you expect, check other tools.
Related reading
- Seeking useful Eclipse Java code templates
- Select N random elements from a List efficiently without toArray and change the list
- Send Custom Java Objects to Kafka Topic
- send multipart response in spring boot
- Sending Email in Android using JavaMail API without using the default/built-in app
- Sending HTTP POST Request In Java
- Sentiment Analysis java Library
- Serializable Inheritance
System design interview problems on this topic
- Design an API Rate Limiter: solution and walkthrough
- Design a Distributed Messaging System: solution and walkthrough
- Design an Online Payment Service: solution and walkthrough
- Design a Key Value Store: solution and walkthrough

OOD Fundamentals
Master object-oriented design from first principles, SOLID, design patterns, and classic interview problems with hands-on coding.
View the courseData 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.