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

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
How to check Java on your macbook - Apple Community
If it is installed, it will print out the version. If it is not installed, it will ask if you want to install it. Choose wisely. ... Try opening an app or website that requires Java. If it needs to, it will be installed ... There are two different Java distributions for the Mac: one distributed ... More on discussions.apple.com
🌐 discussions.apple.com
January 3, 2014
Where is Java Installed on Mac OS X? - TechRepublic
Hi I just downloaded Java 7u17 on Mac OS 10.7.5 then successfully installed it. In order to do some JNI programming, I need to know where Java installed on my Mac. I thought that inside the /Library/Java/JavaVirtualMachines/ folder, there would be a folder called 1.7.0.jdk or something, but ... More on techrepublic.com
🌐 techrepublic.com
March 15, 2022
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
🌐
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.
🌐
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
🌐
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:
🌐
Wikihow
wikihow.com › computers and electronics › software › programming › java › how to check java version on a mac: 2 simple methods
How to Check Java Version on a Mac: 2 Simple Methods
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.
Find elsewhere
🌐
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 ...
🌐
Reddit
reddit.com › r/javahelp › wrong java version showing in terminal on macos and lubuntu.
r/javahelp on Reddit: Wrong Java version showing in Terminal on MacOS and Lubuntu.
September 26, 2021 -

Hi folks, I'm on MacOS 11.6 and have a Java JDK question - hopefully this is the right place for it.

I've got a Java assignment for which I'm required to use the Liberica 11 JDK. It's installed - Eclipse has it and can find it.

I used to also have an OpenJDK version installed, but I've removed that (or at least, I thought I have!)

In Terminal,

java -version 

gives

openjdk version "11.0.10" 2021-01-19 LTS
OpenJDK Runtime Environment (build 11.0.10+9-LTS)
OpenJDK 64-Bit Server VM (build 11.0.10+9-LTS, mixed mode)

In Library/Java/Java Virtual Machines only the Liberica JDK is showing.

I've tried adding it to my path (not 100% sure about how to do this, so may not have done it correctly) but this didn't make a difference to the output.

As a 'what am I missing?' exercise, I tried installing Liberica 11 JDK on a fresh Lubuntu install - it previously had no Java version installed. before install, running java -version gave an error. After installing, java -version gives the same output as on MacOS (openJDK etc).

Is there actually a problem here (i.e. is OpenJDK still the active version on my Mac, does Liberica 11 JDK report the version to be OpenJDK?)

Any help gratefully received!

🌐
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 ...
🌐
Uakron
cs.uakron.edu › ~xiao › isp › JavaOnMacOS.html
Installing Java on MacOS
First, let's check if we already have Java installed on our system. Open up Terminal by pressing 'Command + Space' on your keyboard ... If you get a message that says something like: 'java version "15" 2020-09-15', then you already have Java installed.
🌐
Snyk
snyk.io › blog › installing-and-managing-java-on-macos
Installing and managing Java on macOS | Snyk
October 12, 2023 - This command adds an export line to your .bash_profile file so that the JAVA_HOME variable is set every time you start a new terminal session. /usr/libexec/java_home calls a Java_Home script that returns the path to a Java runtime installation. Ensure the location has backticks around it (`), not single quotation marks ('). Manually installing Java on macOS may seem straightforward, but several aspects can make it difficult and time-consuming, particularly for developers new to Java or macOS.
🌐
Mkyong
mkyong.com › home › java › how to check the installed jdk version on your computer
How to check the installed JDK version on your computer - Mkyong.com
November 26, 2024 - We can use the command java -version to check the installed JDK version on your computer. ... On Windows, open the Command Prompt cmd. On macOS or Linux, open the Terminal.
🌐
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
🌐
Apple Community
discussions.apple.com › thread › 5740534
How to check Java on your macbook - Apple Community
January 3, 2014 - The Oracle Java runtime is a web plugin only. It's used to run Java applets on web pages and Java WebStart applications. You can determine whether it's installed and up to date by looking for a preference pane named Java in System Preferences. If it's present, open it.
🌐
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 ...
🌐
TechRepublic
techrepublic.com › home › topics › operating systems › mac os › where is java installed on mac os x?
Where is Java Installed on Mac OS X? - TechRepublic
March 15, 2022 - In order to do some JNI programming, I need to know where Java installed on my Mac. I thought that inside the /Library/Java/JavaVirtualMachines/ folder, there would be a folder called 1.7.0.jdk or something, but then I found that the folder is empty. This was confirmed by running ls /Library/Java/JavaVirtualMachines/ in the Terminal.
🌐
Codemia
codemia.io › knowledge-hub › path › see_all_the_java_versions_installed_on_mac
See all the Java versions installed on Mac
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises
🌐
Oreate AI
oreateai.com › blog › how-to-check-your-java-version-on-windows-and-mac › 9d87c41da62b664106c7f0582aacda75
How to Check Your Java Version on Windows and Mac - Oreate AI Blog
December 31, 2025 - Terminal Command: Alternatively, if you'd rather use Terminal (found under Applications > Utilities), simply type java -version into that window as well; you'll receive similar output detailing what you've got running.
🌐
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