How to Check Java Version on Linux
Checking the Java version on Linux is an essential task for developers and system administrators alike. It ensures that the correct version of Java is installed and used by applications on the system. This article provides a step-by-step guide on how to check the Java version on various Linux distributions.
Using the `java -version` Command
The most straightforward method to check the Java version on Linux is by using the `java -version` command. This command displays the version of Java that is currently installed on your system. To use this command, open a terminal and type the following:
“`
java -version
“`
The output will display the Java version, along with additional information such as the implementation vendor and the build date. For example:
“`
openjdk version “11.0.10” 2021-01-19
OpenJDK Runtime Environment (build 11.0.10+9-Ubuntu-0ubuntu1.20.04.1)
OpenJDK 64-Bit Server VM (build 11.0.10+9-Ubuntu-0ubuntu1.20.04.1, mixed mode, sharing)
“`
Using the `java` Command
Another way to check the Java version is by using the `java` command without the `-version` flag. This command will display the Java version and the path to the Java executable. To use this command, open a terminal and type:
“`
java
“`
The output will look something like this:
“`
java version “11.0.10” 2021-01-19
Java(TM) SE Runtime Environment (build 11.0.10+9-Ubuntu-0ubuntu1.20.04.1)
Java HotSpot(TM) 64-Bit Server VM (build 11.0.10+9-Ubuntu-0ubuntu1.20.04.1, mixed mode, sharing)
“`
Using the `javac` Command
The `javac` command is the Java compiler, and it can also be used to check the Java version. To use this command, open a terminal and type:
“`
javac -version
“`
The output will display the Java version and the version of the Java compiler:
“`
javac 11.0.10
“`
Using the `update-alternatives` Command
On some Linux distributions, such as Ubuntu, you can use the `update-alternatives` command to manage multiple Java versions. To check the Java version using this command, type:
“`
update-alternatives –config java
“`
This command will display a list of available Java versions and their priorities. Select the version you want to use and press Enter.
Conclusion
Checking the Java version on Linux is a simple process that can be done using various commands. Whether you are a developer or a system administrator, knowing the Java version on your system is crucial for maintaining and troubleshooting applications. By following the steps outlined in this article, you can easily determine the Java version on your Linux system.