Top answer
1 of 11
293

javac -version in a terminal will do

2 of 11
115

You can leverage the java_home helper binary on OS X for what you're looking for.

To list all versions of installed JDK:

Copy$ /usr/libexec/java_home -V
Matching Java Virtual Machines (2):
    1.8.0_51, x86_64:   "Java SE 8" /Library/Java/JavaVirtualMachines/jdk1.8.0_51.jdk/Contents/Home
    1.7.0_79, x86_64:   "Java SE 7" /Library/Java/JavaVirtualMachines/jdk1.7.0_79.jdk/Contents/Home

To request the JAVA_HOME path of a specific JDK version, you can do:

Copy$ /usr/libexec/java_home -v 1.7
/Library/Java/JavaVirtualMachines/jdk1.7.0_79.jdk/Contents/Home

$ /usr/libexec/java_home -v 1.8
/Library/Java/JavaVirtualMachines/jdk1.8.0_51.jdk/Contents/Home

You could take advantage of the above commands in your script like this:

CopyREQUESTED_JAVA_VERSION="1.7"
if POSSIBLE_JAVA_HOME="$(/usr/libexec/java_home -v $REQUESTED_JAVA_VERSION 2>/dev/null)"; then
    # Do this if you want to export JAVA_HOME
    export JAVA_HOME="$POSSIBLE_JAVA_HOME"
    echo "Java SDK is installed"
else
    echo "Did not find any installed JDK for version $REQUESTED_JAVA_VERSION"
fi

You might be able to do if-else and check for multiple different versions of java as well.

If you prefer XML output, java_home also has a -X option to output in XML.

Copy$ /usr/libexec/java_home --help
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.
🌐
Oracle
java.com › en › download › help › version_manual.html
How to find Java version in Windows or Mac - Manual method
You can determine which version of the JDK is the default by typing java -version in a Terminal window. If the installed version is 7u55, you will see a string that includes the text 1.7.0_55.
Discussions

macos - See all the Java versions installed on Mac - Stack Overflow
How can I get all the Java versions installed on my Mac? Is there a terminal command for this? When I run java -version, I get the current JRE version that is in use in my system, but I want to lis... More on stackoverflow.com
🌐 stackoverflow.com
Where is Java installed on MacOS?
My understanding is that the real executable is in Library directory. /use/bin/javac is simply using the the one in Library. To verify it, you can try to delete the Java virtual machine directory. More on reddit.com
🌐 r/MacOS
2
3
November 30, 2022
macos - Determining the version of Java SDK on the Mac - Stack Overflow
I have a MacBook Pro running Snow Leopard; how can I see what version of the Java SDK is installed on my Mac? ... You'll get much better answers if you properly tag your questions, properly word your questions and accept answers ... Open a terminal and type: java -version, or javac -version. More on stackoverflow.com
🌐 stackoverflow.com
Wrong Java version showing in Terminal on MacOS and Lubuntu.
It is build from OpenJDK as they state on their readme on GitHub. I also installed Liberica JDK 11 on a clean VM and I am getting the a silmilar output on version retrieval as yours. The difference is that mine is a the current version. openjdk version "11.0.12" 2021-07-20 LTS OpenJDK Runtime Environment (build 11.0.12+7-LTS) OpenJDK 64-Bit Server VM (build 11.0.12+7-LTS, mixed mode) More on reddit.com
🌐 r/javahelp
9
3
September 26, 2021
People also ask

Can I manage multiple Java versions on Mac?
Yes, using tools like jenv, you can install, switch, and manage multiple Java versions smoothly.
🌐
tataneu.com
tataneu.com › home › consumer electronics › mac java version checklist: quick steps to verify
Mac Java Version Checklist: Quick Steps to Verify
How do I find the JDK version on Mac?
Run 'javac -version' in the Terminal. If JDK is installed, it will return the version number.
🌐
tataneu.com
tataneu.com › home › consumer electronics › mac java version checklist: quick steps to verify
Mac Java Version Checklist: Quick Steps to Verify
How do I update Java on macOS?
Download the newest version from the official website or use Homebrew for updates via the Terminal.
🌐
tataneu.com
tataneu.com › home › consumer electronics › mac java version checklist: quick steps to verify
Mac Java Version Checklist: Quick Steps to Verify
🌐
Mac Install Guide
mac.install.guide › java › version
Check Java Version on Mac · Mac Install Guide · 2026
How to check Java version on Mac with java -version in terminal. Find your JDK location, list installed Java versions, and troubleshoot macOS Java issues.
🌐
Wikihow
wikihow.com › computers and electronics › software › programming › java › how to check java version on a mac: 2 simple methods
How to Quickly and Easily Check Java Version on a Mac
September 28, 2025 - To check the Java version on your Mac, open System Settings and select the "Java" menu item. You can open a terminal and type the command java -version to see your Java version.
🌐
PhoenixNAP
phoenixnap.com › home › kb › sysadmin › how to check java version on mac
How to Check Java Version on Mac (2 Simple Options)
December 16, 2025 - 2. Type Terminal and open it by selecting the relevant search result. ... The output displays the Java version installed on macOS. To check the version of the primary Java compiler (javac), use the command below:
🌐
Intercom
intercom.help › all collections › printers and scales › troubleshooting › how to check java version in windows or mac
How to Check Java Version in Windows or Mac | Upright Labs Help Center
March 4, 2024 - In it, type the command java -version and hit Enter on your keyboard · The output should display the Java version installed on your Mac system ​Note: This should say OpenJDK version 11.x
Find elsewhere
🌐
HubSpot
blog.hubspot.com › home › website › how to check your java version in windows & mac
How to Check Your Java Version in Windows & Mac
February 27, 2025 - This will bring up the command line. From here, you enter the same command as in Windows, java -version to get your current version details. Worth noting? On both Windows and Mac devices, you can use the command javac -version to check the version ...
🌐
Tata Neu
tataneu.com › home › consumer electronics › mac java version checklist: quick steps to verify
Mac Java Version Checklist: Quick Steps to Verify
May 5, 2025 - To determine if the JDK is installed, enter javac -version in your Terminal. This command helps you determine java version mac as it returns the JDK version number. If an error is shown, it may indicate that the check installed java version ...
🌐
Quora
quora.com › How-do-I-check-if-Java-is-installed-on-Mac
How to check if Java is installed on Mac - Quora
Answer (1 of 9): In the Terminal, type “[code ]java -version[/code]” and press Return. Hopefully you get something like this: > java version "1.8.0_261" Java(TM) SE Runtime Environment (build 1.8.0_261-b12) Java HotSpot(TM) 64-Bit Server VM (build 25.261-b12, mixed mode) But if it’s not ...
🌐
Linux Hint
linuxhint.com › check-java-version-mac
How to Check Java Version on Mac – Linux Hint
Some applications even require a specific version of Java to function. To find the Java version on macOS based systems, you need to access the Java Control Panel which appears in the last row of the System Preferences after installing the Java Runtime Environment; Java version can also be checked ...
🌐
Uprightlabs
help.uprightlabs.com › en-us › lister › how-to-check-java-version-in-windows-or-mac
How to Check Java Version in Windows or Mac
A new window with the terminal should appear on your desktop. In it, type the command java -version and hit Enter on your keyboard · The output should display the Java version installed on your Mac system ​Note: This should say OpenJDK version 11.x
🌐
Oracle
docs.oracle.com › javase › › 9 › install › installation-jdk-and-jre-macos.htm
8 Installation of the JDK and the JRE on macOS
There can be multiple JDKs installed on the macOS system. You can determine which version of the JDK is the default by entering java -version in a Terminal window. If the installed version is 9 Minor 1, Security 1, Patch 1, then you see a string that includes the text 9.1.1.1.
🌐
JavaBeat
javabeat.net › home › how to check java version? windows | mac | linux
How to Check Java Version? Windows | Mac | Linux
May 6, 2024 - To check the Java version on Windows, Linux, or Mac operating systems, run the “java --version” command from the respective terminal.
🌐
Rbind
justinbagley.rbind.io › 2020 › 01 › 05 › how-to-check-java-version-on-mac
How to check Java version and JDK version on Mac - blog
January 5, 2020 - Simply open a shell interpreter ... as the Terminal application, and type ... The Java executable on your local machine will output the appropriate Java versioning information. And voilà, you’re done! On my machine, the sanitized version of this procedure looks like: $ java --version openjdk ...
🌐
Princeton CS
introcs.cs.princeton.edu › java › 15inout › mac-cmd.html
Java and the Mac OS X Terminal
You should now have a Terminal window somewhere on the screen. It will have a prompt that looks something like: ... To check that you are running the right version of Java, type the commands in boldface below. You should see something similar to the information printed below. The important part is that it says 1.6 or 1.5 (and not 1.4). machine:~ wayne$ java -version java version "1.6.0_26" Java(TM) SE Runtime Environment (build 1.6.0_26-b03-384-10M3425) Java HotSpot(TM) 64-Bit Server VM (build 20.1-b02-384, mixed mode) Then type
🌐
Quora
quora.com › Is-Java-installed-on-my-Mac
Is Java installed on my Mac? - Quora
Originally Answered: How do I check ... on Mac? · · If Java is installed, it will appear in the System Preferences ... Stake: Online Casino games - Play & Win Online. Play the best online casino games, slots & live casino games! Unlock VIP bonuses, bet with crypto & win. ... Just try by using echo $(/usr/libexec/java_home) command in your terminal to know the path where JAVA being installed. Also try to check the version of JAVA installed ...
🌐
Reddit
reddit.com › r/macos › where is java installed on macos?
r/MacOS on Reddit: Where is Java installed on MacOS?
November 30, 2022 -

On my system, I see that java is installed on /usr/bin AND /Library/Java/JavaVirtualMachines/jdk-17.0.3.1.jdk/Contents/Home/bin. When I type which java in terminal, it says /usr/bin. So, why is it installed in two directories? (I know I can change the directory by typing the second directory first in the $PATH file, but my question is why are there two binaries and if I should remove one of the two. Also, each file is unique and not an alias of the other). Thank you

🌐
Medium
medium.com › @akhiltheguitarist › setting-up-java-path-on-macos-11d51e89a55f
Setting up java path on macOS. So recently, I changed my work machine… | by akhil | Medium
September 24, 2021 - It is a bit different to set up on a mac, than in windows. To keep it short, following the below steps helps set the required java home path. ... Pre-requisite: You must have java downloaded and installed on your system. Step 1: View the available java version on the system. Open up terminal and ...