1. Overview

In this short tutorial, we’re going to take a look at a few ways to determine if Java is installed on a machine.

2. Command Line

First, let’s open a command window or terminal and enter:

> java -version

If Java is installed and the PATH is configured correctly, our output will be similar to:

java version "1.8.0_31"
Java(TM) SE Runtime Environment (build 1.8.0_31-b13)
Java HotSpot(TM) Client VM (build 25.31-b07, mixed mode, sharing)

Otherwise, we’ll see an error message like the one below and we need to check elsewhere:

'java' is not recognized as an internal or external command,
operable program or batch file.

The exact messages we see will vary depending on the operating system used and the Java version installed.

3. When Path Is Not Set

Going to a command line and typing java -version can tell us for sure if Java is installed. However, if we see an error message, Java might still be installed – we’ll just need to investigate further.

Many discussions about using java -version mention the JAVA_HOME environment variable. This is misleading because JAVA_HOME won’t affect our java -version results.

Additionally, JAVA_HOME should point to a JDK and other applications that use JDK features, such as Maven, use it.

For more information, please check our articles JAVA_HOME should point to a JDK and how to set JAVA_HOME.

So, let’s look at alternative ways to find Java, in case the command-line failed us.

3.1. Windows 10

On Windows, we can find it in the Application list:

  1. Press the Start Button
  2. Scroll down the application list to J
  3. Open the Java folder
  4. Click About Java
how to check if java installed windows apps about java

We can also look at installed Programs and Features:

  1. In the Search bar, type Control Panel
  2. Click Programs
  3. If the Java icon present, then Java is installed
  4. If not, click Programs and Features, and look for installed versions of Java in the J’s
how to check if java installed windows programs features

3.2. Mac OS X

To see if Java 7 or greater is installed on a Mac we can:

  1. Go to System Preferences
  2. Look for the Java icon
how to check if java installed mac sys prefs

For earlier versions of Java, we’ll need to:

  1. Open Finder
  2. Go to the Applications folder
  3. Go to the Utilities folder
  4. Look for the Java Preferences app

3.3. *Nix

There are few different package managers in the *nix world.

In a Debian-based distribution, we can use the aptitude search command:

$ sudo aptitude search jdk jre

If there is an i before the result, then that means the package is installed:

i   oracle-java8-jdk                - Java™ Platform, Standard Edition 8 Develop

4. Other Command Line Tools

In addition to java -version, there are some other command line tools we can use to learn about our Java installation.

4.1. Windows where Command

In Windows, we can use the where command to find where our java.exe is located:

> where java

And our output will look something like:


However, as with java -version, this command is only useful if our PATH environment variable points to the bin directory.

4.2. Mac OS X and *nix which and whereis

In a *nix system or on a Mac in the Terminal app, we can use the which command:

$ which java

The output tells us where the Java command is:


Now let’s use the whereis command:

$ whereis java -b

The whereis command also gives us the path to our Java installation:


As with java -version, these commands will only find Java if it’s on the path. We can use these when we have Java installed but want to know exactly what’s going to run when we use the java command.

5. Conclusion

In this short article, we discussed how to find out if Java is installed on a Windows 10, Mac OS X or Linux/Unix machine even if it’s not on the PATH.

We also looked at a couple useful commands for locating our Java installation.

Course – LS (cat=Java)

Get started with Spring and Spring Boot, through the Learn Spring course:

res – REST with Spring (eBook) (everywhere)
Comments are open for 30 days after publishing a post. For any issues past this date, use the Contact form on the site.