Is there a way to find the complete list of Java versions installed on OS X?

Viewed 5230

I was trying to find the complete list of JDK versions installed on my Mac OS X.

I did try with javac -version but it only shows the current version that is set in bashrc.

Any help would be appreciated.

2 Answers

Mac OS X has a cool binary (/usr/libexec/java_home) that returns the path to a Java home directory from the current user's settings. You may want to issue:

/usr/libexec/java_home -V

It prints the full JVM list with architectures like this:

Matching Java Virtual Machines (2):
    13, x86_64: "OpenJDK 13"    /Library/Java/JavaVirtualMachines/openjdk-13.jdk/Contents/Home
    1.8.0_265, x86_64:  "AdoptOpenJDK 8"    /Library/Java/JavaVirtualMachines/adoptopenjdk-8.jdk/Contents/Home

/Library/Java/JavaVirtualMachines/openjdk-13.jdk/Contents/Home

If you want to print the JAVA_HOME path of a specific JDK version, you can do it like this:

/usr/libexec/java_home -v 1.8
/Library/Java/JavaVirtualMachines/adoptopenjdk-8.jdk/Contents/Home

You can see the complete usage options of below:

Usage: java_home [options...]
    Returns the path to a Java home directory from the current user's settings.

Options:
    [-v/--version   <version>]       Filter Java versions in the "JVMVersion" form 1.X(+ or *).
    [-a/--arch      <architecture>]  Filter JVMs matching architecture (i386, x86_64, etc).
    [-d/--datamodel <datamodel>]     Filter JVMs capable of -d32 or -d64
    [-t/--task      <task>]          Use the JVM list for a specific task (Applets, WebStart, BundledApp, JNI, or CommandLine)
    [-F/--failfast]                  Fail when filters return no JVMs, do not continue with default.
    [   --exec      <command> ...]   Execute the $JAVA_HOME/bin/<command> with the remaining arguments.
    [-R/--request]                   Request installation of a Java Runtime if not installed.
    [-X/--xml]                       Print full JVM list and additional data as XML plist.
    [-V/--verbose]                   Print full JVM list with architectures.
    [-h/--help]                      This usage information.

You can use the java_home binary for this task.

/usr/libexec includes internal binaries that are not intended to be executed directly by users or shell scripts. java_home is one such binary, calling it with option -V will print full JVM list with architectures.

     /usr/libexec/java_home -V
Related