Java is one of the most popular programming languages in the world, used for building different types of cross-platform applications.
This article explains how to check what version of Java is installed on your Linux system using the command line. This can be useful when installing applications that require a specific version of Java.
Java Versioning
Java uses semantic versioning . Production-ready releases are versioned in the following scheme:
MAJOR.MINOR.SECURITY
For example, in Java 11.0.8, 11
is a major version, 0
is a minor version, and 8
is a security version.
MAJOR
– Major releases are bringing new features and functions.MINOR
– Minor releases contain various bug fixes and compatible improvements.SECURITY
– Security releases provide critical security fixes.
Checking Java Version
To find out which Java version is installed on your system, run the java -version
command:
java -version
The command will display the default Java version:
openjdk 11.0.8 2020-07-14
OpenJDK Runtime Environment (build 11.0.8+10-post-Ubuntu-0ubuntu120.04)
OpenJDK 64-Bit Server VM (build 11.0.8+10-post-Ubuntu-0ubuntu120.04, mixed mode, sharing)
In this example, we have Java version 11.0.8
installed on our system. The version installed on your system may be different.
If you get “java: command not found” it means that Java is no installed on the system. To install Java, use one of the following guides, depending on your Linux distribution:
The system may also have multiple versions of Java installed at the same time. To check whether you have multiple Java installations on your machine run:
sudo update-alternatives --config java
If you have only one Java installation, the output will look something like this:
There is only one alternative in link group java (providing /usr/bin/java): /usr/lib/jvm/java-11-openjdk-amd64/bin/java
Nothing to configure.
Otherwise, if you have multiple Java installations, the command will display a menu where you can select which version will be the default Java version:
There are 3 choices for the alternative java (providing /usr/bin/java).
Selection Path Priority Status
------------------------------------------------------------
* 0 /usr/lib/jvm/java-11-openjdk-amd64/bin/java 1111 auto mode
1 /usr/lib/jvm/java-11-openjdk-amd64/bin/java 1111 manual mode
2 /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java 1081 manual mode
Press <enter> to keep the current choice[*], or type selection number:
To change the default Java version, just enter the version number (the number in the Selection column) and press Enter
.
Conclusion
Finding out what Java version is installed on your Linux system is very easy, just type java -version
.
Feel free to leave a comment if you have any questions.