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 is the system currently using.
This article describes how you can easily check your installed Java version on your Ubuntu system. We have run the commands and procedures mentioned in this article on a Ubuntu 18.04 LTS system.
We will be using the Ubuntu command line, the Terminal, in order to run all the mentioned commands. You can open the Terminal application either through the 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 in order to check it’s version:
$ java -version
$ java --version
This will ensure whether Java Runtime Environment is already installed on your system or not. 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.
If you have any version of Java installed on your system, the output will display Java OpenJDK and JRE version information as follows:
Method 2: By checking the path where Java is installed
Enter the following command in order 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:
However, if Java is installed on your system this command will show the exact path where Java is installed:
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 in order 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 which have the ‘i’ prefix with them are installed on your system.
In the above output, you can see that Java OpenJDK 11 JRE is installed on my system. If you do not see the ‘i’ prefix with any of the JDK entries, that means that Java is not installed on your system.
Through these simple ways, you can verify if Java is installed on your system or not. You can also view which Java installation you have on your system if it is indeed installed.