See all the Java versions installed on Mac
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Introduction
To see all Java versions installed on a Mac, run /usr/libexec/java_home -V in Terminal. This built-in macOS utility lists every JDK it can find under /Library/Java/JavaVirtualMachines/, showing the version number, architecture, vendor, and installation path for each one.
Sample output:
Why Multiple Java Versions Exist on One Machine
Different projects often pin different Java versions. A legacy service might require Java 11 while a newer microservice targets Java 21. Build tools like Maven and Gradle respect JAVA_HOME, so switching versions per project is a normal part of Java development on macOS.
Homebrew, SDKMAN!, and manual .pkg installers all place JDKs in the same /Library/Java/JavaVirtualMachines/ directory, which is why multiple versions accumulate over time.
Checking the Active Java Version
The java_home -V command shows what is installed, but to see which version the current shell session is actually using, run:
This reports the version that the java binary on your PATH resolves to. If JAVA_HOME is set, most build tools use that value instead of whatever java -version reports.
To see exactly which binary your shell resolves:
On modern macOS, this often points to /usr/bin/java, which is a shim that delegates to the JDK selected by java_home.
Switching Between Installed Versions
Setting JAVA_HOME Manually
The java_home utility can return the path for a specific version, which you can assign to JAVA_HOME:
Add this line to your ~/.zshrc (or ~/.bash_profile for older macOS) to make it persistent. To switch versions, change the version number and reload your shell:
Switching With a Shell Function
A shell function makes switching faster during active development:
Usage:
Using SDKMAN!
SDKMAN! is a version manager that handles installation and switching in one tool:
SDKMAN! installs JDKs to ~/.sdkman/candidates/java/ rather than the system directory, so java_home -V will not list them. Use sdk list java instead when managing versions through SDKMAN!.
Comparison of Methods
| 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 |
Finding JDK Installation Paths
All standard macOS JDK installers place files under:
You can list the directories directly:
Each JDK lives in its own directory, typically named with the vendor and version:
The actual JAVA_HOME path points one level deeper:
Removing Old Java Versions
Uninstalling a JDK is a matter of removing its directory:
If the JDK was installed via Homebrew:
If installed via SDKMAN!:
After removal, run /usr/libexec/java_home -V again to confirm the version is gone.
Checking Java Versions in Build Tools
Build tools have their own ways to report the Java version they are using:
If the version reported by your build tool does not match java -version, check whether the tool has its own JAVA_HOME override in its configuration or wrapper script.
Apple Silicon vs. Intel Considerations
On Apple Silicon Macs, the architecture column in java_home -V output shows arm64. If you also have Rosetta-translated Intel JDKs installed, they appear as x86_64. Both architectures can coexist, but mixing them in the same build can cause issues with native libraries.
To filter by architecture:
Common Pitfalls
Running java -version and assuming it reflects what your IDE or build tool uses is a frequent mistake. IDEs like IntelliJ IDEA maintain their own JDK configuration independent of JAVA_HOME. Always check the IDE's project settings separately.
Forgetting to reload the shell after editing ~/.zshrc means the JAVA_HOME change is not picked up. Run source ~/.zshrc or open a new terminal window after making changes.
Installing JDKs through multiple package managers (Homebrew, SDKMAN!, manual .pkg) leads to confusion about which versions exist where. Pick one manager and stick with it for consistency.
The java_home utility only scans /Library/Java/JavaVirtualMachines/. JDKs installed elsewhere (such as SDKMAN!'s ~/.sdkman/ directory) are invisible to it. If java_home -V shows fewer versions than you expect, check whether some were installed by a different tool.
Summary
- Run
/usr/libexec/java_home -Vto list all system-installed JDKs on macOS. - Use
java -versionto check which version the current shell session is using. - Set
JAVA_HOMEwithexport JAVA_HOME=$(/usr/libexec/java_home -v VERSION)to switch versions. - Use SDKMAN! for a more integrated install-and-switch workflow.
- Remove old JDKs by deleting their directory under
/Library/Java/JavaVirtualMachines/. - Be aware that
java_homedoes not see JDKs managed by SDKMAN! or installed outside the system directory.

