Everywhere All articles Download Buy — $19

Where apps hide your files

Finding your JDKs and JAVA_HOME

Updated 2026-10-28 · 5 min read

Java on a Mac is not one install but a folder of them, one per JDK, plus private copies bundled inside IDEs. The tool that lists them and prints the right JAVA_HOME already ships with macOS.

The location

/Library/Java/JavaVirtualMachines

Each JDK installed with a package installer gets its own .jdk folder here, such as temurin-20.jdk or jdk-19.jdk. The folder you want for JAVA_HOME is inside it:

/Library/Java/JavaVirtualMachines/<name>.jdk/Contents/Home

Open the parent in Finder with Go > Go to Folder (⇧⌘G), or run open /Library/Java/JavaVirtualMachines.

Let macOS tell you

You do not need to guess. This lists every JDK it can find, with version, architecture and path:

/usr/libexec/java_home -V

On the Mac used for this guide it lists two: a Temurin 20 build for x86_64 and an Oracle Java 19 build for arm64, each with its Contents/Home path. Without -V it prints just the path of the default one, and with -v you ask for a version:

/usr/libexec/java_home -v 20

Apple's own usage text also documents -a to filter by architecture and -F to fail instead of falling back to a default. On an Apple silicon Mac that matters, because an Intel JDK and an Apple silicon JDK can both be present.

Setting JAVA_HOME

Put this in ~/.zshrc, so each new Terminal window picks the JDK you ask for:

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

Change the number to the major version you want. If that version is not installed, java_home quietly falls back to the default JDK (on the Mac used here, -v 17 printed the Java 20 path), so add -F to make it fail instead. Reload with source ~/.zshrc and check with echo $JAVA_HOME. Apps launched from the Dock do not read ~/.zshrc, so an IDE or a GUI tool uses its own setting. That is the usual reason a build works in Terminal and fails in an app.

Picking a JDK for one command

You do not have to change JAVA_HOME for everything. java_home can run a tool from a chosen JDK with its --exec option:

/usr/libexec/java_home -v 19 --exec java -version

A variable set inline applies only to that one command:

JAVA_HOME=$(/usr/libexec/java_home -v 19) ./gradlew build

That is handy for one project that needs an older Java than your default. Use the -a arm64 filter the same way when a build needs the native Apple silicon JDK rather than an Intel one.

Why /usr/bin/java is not a JDK

The java at /usr/bin/java is a launcher stub, not a copy of Java. It runs the JDK in JAVA_HOME when you have set it, and otherwise asks java_home for the default. On the Mac used here /usr/bin/java -version reported the Temurin 20 build, matching the first line of java_home -V. With no JDK installed, the stub shows a message instead of running anything, so a bare java command is a quick test of whether a JDK is visible at all.

Other places a Java can hide

LocationWhat it is
~/Library/Java/JavaVirtualMachinesPer-user JDKs. java_home scans it too, but the folder only exists if something created it.
/opt/homebrew/opt/openjdkHomebrew's OpenJDK on Apple silicon, with the JDK itself in libexec/openjdk.jdk. Intel Homebrew uses /usr/local/opt/openjdk.
~/.sdkman/candidates/javaJDKs installed by SDKMAN, if you use it.
~/.gradle/jdksJDKs Gradle downloads for toolchains when a build asks for a Java you do not have.
/Applications/Android Studio.app/Contents/jbrThe runtime bundled inside Android Studio, with a Contents/Home of its own.

Homebrew's OpenJDK is keg-only and is not seen by java_home until you link it. The formula's caveats print the exact ln -sfn command to place it in /Library/Java/JavaVirtualMachines; run brew info openjdk to read it for your version. The ~/.gradle/jdks and jbr folders are private to those tools and are not found by java_home. Delete a Gradle-downloaded JDK and Gradle downloads it again the next time a build needs it, provided the build is set up to provision toolchains automatically.

Removing a JDK

For a package-installed JDK, quit anything using Java, then move the whole .jdk folder from /Library/Java/JavaVirtualMachines to the Trash in Finder (it asks for your password). Do not delete only Contents/Home. Each folder on the Mac used here was around 300 MB.

If your Mac then still reports a Java you thought was gone, run /usr/libexec/java_home -V again: it will name the one that remains, and any JAVA_HOME line in ~/.zshrc that points at the deleted folder needs updating or the next build fails with a missing path.

To see how much space your JDKs take before deciding, run du -sh /Library/Java/JavaVirtualMachines/*. It only reads sizes.

Why search misses these files

/Library/Java is outside your home folder, and a JDK is thousands of files with names like libjvm.dylib and java that Finder searches rarely surface. A .jdk is an ordinary folder, but the files that matter sit three or four levels down inside Contents/Home.

Finding a JDK next time

Everywhere indexes system folders and the inside of app bundles too, so typing jdk lists every .jdk folder on the Mac, and typing jbr finds the runtime an IDE ships inside itself. Press ⌘↵ to reveal one. It searches file names only, so use java_home -V to see which version each folder holds.

Common questions

Where is Java installed on a Mac?

In /Library/Java/JavaVirtualMachines, one .jdk folder per JDK. The JAVA_HOME path is the Contents/Home folder inside the one you want.

How do I find JAVA_HOME on a Mac?

Run /usr/libexec/java_home for the default JDK, or /usr/libexec/java_home -V to list all of them with versions and architectures.

How do I switch Java versions on a Mac?

Set JAVA_HOME to $(/usr/libexec/java_home -v <version>) in ~/.zshrc, then open a new Terminal window. IDEs have their own JDK settings.

Why does java -version show a different Java than I installed?

/usr/bin/java runs the JDK in JAVA_HOME if it is set, otherwise the default java_home picks, and a Homebrew java earlier in your PATH can win over both. Check which -a java and /usr/libexec/java_home -V, then set JAVA_HOME explicitly.

Find any file before you finish typing

Everywhere keeps track of every file on your Mac — including the folders Spotlight hides and drives you have unplugged. Free for a day, then $19 once.

Version 2.20.3 · macOS 13+ · 4.7 MB · notarised

Related

© 2026 Caretopia Network Private Limited Everywhere for Mac Buy a licence Articles Privacy Support