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.
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:
- Press the Start Button
- Scroll down the application list to J
- Open the Java folder
- Click About Java
We can also look at installed Programs and Features:
- In the Search bar, type Control Panel
- Click Programs
- If the Java icon present, then Java is installed
- If not, click Programs and Features, and look for installed versions of Java in the J’s
3.2. Mac OS X
To see if Java 7 or greater is installed on a Mac we can:
- Go to System Preferences
- Look for the Java icon
For earlier versions of Java, we’ll need to:
- Open Finder
- Go to the Applications folder
- Go to the Utilities folder
- Look for the Java Preferences app
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.
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.