How to Check Java Version in Linux?
Direct Answer:
To check the Java version in Linux, you can use the following command:
java -version
Or, if you have OpenJDK installed, you can use:
openjdk --version
These commands will display the Java version installed on your system.
Understanding the Importance of Checking Java Version
Java is a popular programming language used for developing a wide range of applications, from web applications to Android apps. It’s essential to check the version of Java installed on your system to ensure compatibility with specific applications and to troubleshoot any issues that may arise. In this article, we will explore the various ways to check Java version in Linux and provide you with the necessary information to do so.
Method 1: Using the java Command
The most straightforward way to check the Java version in Linux is by using the java command followed by the -version option. This command will display the Java version installed on your system. Here’s an example:
java -version
Output:
java version "1.8.0_251"
Java(TM) SE Runtime Environment (build 1.8.0_251-b08)
In this example, the output shows that Java 1.8.0_251 is installed on the system.
Method 2: Using the openjdk Command (For OpenJDK Users)
If you have OpenJDK installed on your system, you can use the openjdk command followed by the --version option to check the OpenJDK version. Here’s an example:
openjdk --version
Output:
openjdk 15.0.2 2021-07-20
OpenJDK 64-Bit Server VM ( Adaptive Spinning, Pare-Logo Plot, Worm Variable Holder, Fork-Ahead, Zero-Apollo-Antenna, Fork-Ahead-Ahead)
In this example, the output shows that OpenJDK 15.0.2 is installed on the system.
Method 3: Checking Java Version using the which Command
Another way to check the Java version is by using the which command followed by the java or javac command. This method will display the path to the Java executable and will also indicate if the command is available. Here’s an example:
which java
Output:
/usr/bin/java
In this example, the output shows that the java command is available at the path /usr/bin/java. This method is useful if you want to check if Java is installed on your system and where it’s installed.
Method 4: Checking Java Version using the dpkg Command (For Debian-based Systems)
On Debian-based systems, such as Ubuntu, you can use the dpkg command to check the Java version. Here’s an example:
dpkg -l openjdk-8-jdk
This command will list the details of the OpenJDK 8 installation, including the version. Here’s an example output:
Desired=unknown
State=installed
In this example, the output shows that OpenJDK 8 is installed on the system.
Method 5: Checking Java Version using the rpm Command (For RPM-based Systems)
On RPM-based systems, such as CentOS, you can use the rpm command to check the Java version. Here’s an example:
rpm -qa java-1.8.0-openjdk
This command will list the details of the OpenJDK 1.8.0 installation, including the version. Here’s an example output:
java-1.8.0-openjdk-1.8.0.292-1.1.el7.x86_64
In this example, the output shows that OpenJDK 1.8.0 is installed on the system.
Conclusion
In this article, we have discussed various ways to check the Java version in Linux, including using the java command, openjdk command, which command, dpkg command, and rpm command. By following these methods, you can easily check the Java version installed on your Linux system and troubleshoot any issues that may arise. Remember to always check the Java version to ensure compatibility with specific applications and to resolve any version-related issues.
