← All articles
Java · macOS

Find the Installed Java Home on macOS

macOS includes the /usr/libexec/java_home utility for locating installed Java runtimes. This is useful when configuring JAVA_HOME, IDEs, build tools, or applications that need an explicit JDK path.

Find the Default Java Home

Open Terminal and run:

/usr/libexec/java_home

A system with Java 7 installed might return a path similar to:

/Library/Java/JavaVirtualMachines/jdk1.7.0_79.jdk/Contents/Home

Find a Specific Java Version

Use the -v option to request a particular version:

/usr/libexec/java_home -v 1.7

If a matching runtime is installed, the command returns its home directory.

When the Requested Version Is Missing

For example:

/usr/libexec/java_home -v 1.8

If no matching JVM is available, the utility reports that it cannot find a runtime for the requested version.

Version context: The example paths use Java versions current when this article was written. The same utility can be used with newer JDK installations, although version strings and installation paths will differ.

Takeaway

Prefer java_home over hard-coding a JDK path when you need to discover which Java installation macOS recognizes.

CONTINUE READING

Explore closely related architecture, integration and implementation topics.