How to Check Java Version On Linux | Ubuntu/Debian/CentOS

check java version linux

Java is one of the most popular and widely used programming languages around the globe. If you are a Java developer then you must have a knowledge of “how to check java version”. There are several methods to check which Java version installed in your system.

If you don’t know how to install Java, you should read my guide on How to Install Java on Ubuntu 20.04.

In the post, we will show you how to check java version on CentOS, Ubuntu and Debian operating systems.

Prerequisites

  • A server running Debian 10.
  • A root password is set up in your server.

Check Java Version on Linux

If you want to check the Java version on Ubuntu, Debian or CentOS operating systems, open a command-line terminal and run the following command:

java -version

This will display the installed version of Java as shown below:

java -version
openjdk version "11.0.9.1" 2020-11-04
OpenJDK Runtime Environment (build 11.0.9.1+1-Ubuntu-0ubuntu1.20.04)
OpenJDK 64-Bit Server VM (build 11.0.9.1+1-Ubuntu-0ubuntu1.20.04, mixed mode, sharing)

check java version ubuntu

You can also check the Java compiler version using the javac command as shown below:

javac -version

You should see the Java compiler version in the following output:

javac 11.0.9.1

check javac version linux

Check Java Version Using the Java Installation Path

You can also check the java version with the help of Java installation path. There is two way to find the Java installation directory or path.

The first method to find the Java installation path with the following command:

update-alternatives --list java

This will display the complete path of the Java as shown below:

/usr/lib/jvm/java-11-openjdk-amd64/bin/java

Note: For CentOS and RHEL operating system, run the following command:

update-alternatives --list

You can also use the whereis command to check the Java path.

Run the whereis command as shown below:

whereis java

You should see the following output:

java: /usr/bin/java /usr/share/java /usr/share/man/man1/java.1.gz

Next, run the ls command to list the content of /usr/bin/java:

ls -l /usr/bin/java

You should see the following output:

lrwxrwxrwx 1 root root 22 Feb  5 04:50 /usr/bin/java -> /etc/alternatives/java

In the above output, you should see that /usr/bin/java point to symbolic link /etc/alternatives/java.

Now, run the ls command again to list the content of /etc/alternatives/java.

ls -l /etc/alternatives/java

This will display the complete path of the Java as shown below:

lrwxrwxrwx 1 root root 43 Feb  5 04:50 /etc/alternatives/java -> /usr/lib/jvm/java-11-openjdk-amd64/bin/java

check java version using path

Check Java Version by Searching in Installed Package List

You can also check the Java version to list installed packages and search for Java. For Ubuntu and Debian operating systems, follow the below steps:

You can use either apt or dpkg command to list all installed packages.

List all installed packages and search for Java using the apt command:

apt list --installed | grep -i openjdk

You should see the installed version of Java in the following output:

openjdk-11-jdk-headless/focal-updates,focal-security,now 11.0.9.1+1-0ubuntu1~20.04 amd64 [installed,automatic]
openjdk-11-jdk/focal-updates,focal-security,now 11.0.9.1+1-0ubuntu1~20.04 amd64 [installed,automatic]
openjdk-11-jre-headless/focal-updates,focal-security,now 11.0.9.1+1-0ubuntu1~20.04 amd64 [installed,automatic]
openjdk-11-jre/focal-updates,focal-security,now 11.0.9.1+1-0ubuntu1~20.04 amd64 [installed,automatic]

List all installed packages and search for Java using the dpkg command:

dpkg -l | grep -i openjdk

You should see the installed version of Java in the following output:

ii  openjdk-11-jdk:amd64           11.0.9.1+1-0ubuntu1~20.04         amd64        OpenJDK Development Kit (JDK)
ii  openjdk-11-jdk-headless:amd64  11.0.9.1+1-0ubuntu1~20.04         amd64        OpenJDK Development Kit (JDK) (headless)
ii  openjdk-11-jre:amd64           11.0.9.1+1-0ubuntu1~20.04         amd64        OpenJDK Java runtime, using Hotspot JIT
ii  openjdk-11-jre-headless:amd64  11.0.9.1+1-0ubuntu1~20.04         amd64        OpenJDK Java runtime, using Hotspot JIT (headless)

For CentOS and RHEL operating systems, follow the below steps:

You can use yum or dnf command to list all installed packages and search for Java as shown below:

yum list installed | grep -i openjdk

This will display the installed version of Java as shown below:

java-11-openjdk.x86_64               1:11.0.9.11-3.el8_3                      @AppStream
java-11-openjdk-devel.x86_64         1:11.0.9.11-3.el8_3                      @AppStream
java-11-openjdk-headless.x86_64      1:11.0.9.11-3.el8_3                      @AppStream

Conclusion

In the above guide, you learned a different method of how to check the Java version on Linux. You can now any of the above methods to check the Java version.

About Hitesh Jethva

I am Hitesh Jethva Founder and Author at LinuxBuz.com. I felt in love with Linux when i was started to learn Linux. I am a fan of open source technology and have more than 15+ years of experience in Linux and Open Source technologies.

View all posts by Hitesh Jethva