Verify JAVA Installation on Ubuntu and Check the Installed version (if any)

Certain applications in Ubuntu require that Java Runtime Library is installed on your system. It does not come by default with most Ubuntu versions, as security is a concern when Java is installed on your system. Time and again, a regular Ubuntu user might need to verify if Java is installed on the system at the moment and also if it is installed, which version the system is currently using.

This article describes how you can quickly check your installed Java version on your Ubuntu system. We have tested the commands and procedures mentioned in this article on Ubuntu versions between 18.04 and 22.04.

We will use the Ubuntu command line, the Terminal, to run all the mentioned commands. You can open the Terminal application through Ubuntu Dash or the Ctrl+Alt+T shortcut.

Method 1: Checking the Java version

Once you have opened the Terminal, enter one of the following Java commands to check its version:

$ java -version

Or

$ java --version

This will ensure whether Java Runtime Environment is already installed on your system. If yes, it will also let you know which version of Java you have on your system.

In my case, the output shows that I do not have Java currently installed on my system yet.

No Java installed

If you have any version of Java installed on your system, the output will display Java OpenJDK and JRE version information as follows:

Check installed JAVA version

Method 2: By checking the path where Java is installed

Enter the following command to check the directory in which Java is installed:

$ which java

This command will print no output if Java is not installed on your system:

Java not installed

However, if Java is installed on your system, this command will show the exact path where Java is installed:

Java is installed in /usr/bin folder

Method3: Search for Java in the Installed Packages list

You can check if a software package is installed on your system by using the following command syntax:

$ sudo aptitude search PackageName

We can use this command to see if any JDK package is installed on our system or not:

$ sudo aptitude search jdk

This command will list all the JDK packages available in the Ubuntu repositories.

Please note the prefix with each entry.

Only the packages with the ā€˜iā€™ prefix are installed on your system.

Search for installed JAVA packages

In the above output, you can see that Java OpenJDK 11 JRE is installed on my system. Java is not installed on your system if you do not see the ā€˜iā€™ prefix with any of the JDK entries. A more in-depth guide on finding installed packages can be found here.

Through these simple ways, you can verify whether Java is installed on your system. You can also view which Java installation you have on your system if it is indeed installed.