How to Check Java Version Installed on Linux

Introduction

Java is an object-oriented programming language used for building platform-independent applications. Knowing how to check the Java version on Linux is important as different applications sometimes require specific Java versions, ensuring compatibility and optimal performance.

Additionally, checking the version helps manage updates and maintain a secure, up-to-date Java environment on your system.

In this tutorial, learn how to check the Java version installed on Linux.

How to check Java version on Linux

Prerequisites

  • A user account with sudo or root privileges.
  • Access to the terminal.
  • Java installed.

How to Check Java Version on Linux

There are several ways to check the Java version on Linux. The following text presents three different methods.

Method 1: java -version Command

To check the Java version on Linux, run the following:

java -version
java --version terminal output

The output displays the Java package version installed on your system. In the example above, OpenJDK version 11.0.24 is installed.

Note: If the output indicates there is no such package on the system, learn how to install Java on Ubuntu

Another way to get the Java version is to check the version of the primary Java compiler, javac. Do it with the following command:

javac -version
javac --version terminal output

Method 2: Check Java Path

There are two ways to find the Java directory path. The first option is to run the following command:

update-alternatives --list java
terminal output update-alternatives --list java

The system responds with the path where Java is installed. Use the path to check the Java version:

/usr/lib/jvm/java-11-openjdk-amd64/bin/java -version
terminal output /usr/lib/jvm/java-11-openjdk-amd64/bin/java -version

Alternatively, use the whereis command and follow the symbolic links to find the Java path. To do it, take the following steps:

1. Run the command:

whereis java
whereis java terminal output

The output shows that Java is located in /usr/bin/java.

2. List the /usr/bin/java directory content with the ls command:

ls -l /usr/bin/java
ls -l /usr/bin/java terminal output

The output shows that /usr/bin/java is a symbolic link for /etc/alternatives/java.

3. List the content of the provided path by running:

ls -l /etc/alternatives/java
ls -l /etc/alternatives/java terminal output

The output displays /etc/alternatives/java is another symbolic link and that the actual Java directory path is /usr/lib/jvm/java-11-openjdk-amd64/bin/java.

4. Verify the version with:

<em>/usr/lib/jvm/java-11-openjdk-amd64/bin/java.</em> -version

Method 3: Find Java in Installed Packages

You can also prompt the system to list installed packages and search for Java with its version number.

To generate a list of all installed packages, use the command:

sudo apt list --installed

Scroll up or down until you find the Java packages, as shown in this example.

Find Java packages terminal output

To avoid searching through all installed packages, list Java packages only. Prompt the system to list Java packages by searching for openjdk with grep:

sudo apt list --installed | grep -i openjdk
sudo apt list --installed | grep -i openjdk terminal output

Conclusion

This article explained how to check the Java version on Linux using three different methods.

Next, learn how to install Java on different Linux distributions, such as Raspberry Pi and Fedora.

Was this article helpful?
YesNo
Sara Zivanov
Sara Zivanov is a technical writer at phoenixNAP who is passionate about making high-tech concepts accessible to everyone. Her experience as a content writer and her background in Engineering and Project Management allows her to streamline complex processes and make them user-friendly through her content.
Next you should read
How to Install Nvidia Drivers on Ubuntu 20.04
March 23, 2021

Ubuntu 20.04 comes with an open-source Nouveau GPU driver out of the box. This driver does not always take...
Read more
Bare Metal Cloud Portal Quick Start Guide
March 23, 2021

Follow the sections in this Bare Metal Cloud Portal guide to learn how to navigate through the portal. This...
Read more
How to Deploy a Bare Metal Cloud Server
March 23, 2021

This article shows how to deploy a new Bare Metal Cloud server in nine simple steps. Follow the instructions...
Read more
How to Use the vmstat Command
March 18, 2021

The vmstat command is a Linux monitoring utility used to see various system statistics and to diagnose...
Read more