How to Find the Java Version in Linux?

Introduction
Java is an all-rounder and widely used programming language, powering everything from enterprise-level apps to Android devices. It is integral to software development, web applications, and big data technologies. Ensuring the correct Java version is installed is significant for efficient functioning as well as compatibility.
On Linux systems, checking the Java version is straightforward, thanks to built-in commands and tools. Whether you’re troubleshooting an issue, upgrading Java, or verifying system requirements, learning to verify the Java version on Linux will save time and effort. This guide will walk you through various methods to find the Java version in Linux, including commands and package inspection techniques. With these approaches, you can optimally handle your Java environment on Linux.
What is Java Version?

The Java version refers to the specific release of Java installed on your system. It includes both major and minor versions, each rendering distinguished attributes and enhancements. The Java version you use can directly impact your system’s compatibility, performance, and security. For instance, Java 8 introduced features like Lambda expressions, while Java 11 brought improvements like HTTP client APIs and better garbage collection. Learning how to verify the Java version on Linux helps ensure your environment is optimized for your applications or tools.
Java versions are split into two principal elements:
- Java Development Kit (JDK):
The JDK is essential for developers. It incorporates components for writing, compiling, & debugging programs of Java. If you’re building Java applications or using development tools, checking the JDK version on Linux is crucial. - Java Runtime Environment (JRE):
The JRE is designed to run Java programs. It incorporates the Java Virtual Machine (JVM) & other runtime libraries. To check the JRE version on Linux, you can use similar commands as those for the JDK. This ensures the required runtime environment is in place for your applications.
Why Is Knowing the Java Version Important?
- Compatibility: Some software or tools only support specific Java versions. Checking your Linux Java version prevents compatibility issues.
- Security: Older Java versions may have vulnerabilities. Verifying your version ensures your system uses a secure release.
- Performance: Newer versions of Java offer enhanced performance and better resource management. For instance, updating Java on Linux to the latest version can significantly improve application efficiency.
- Troubleshooting: Knowing the version helps in debugging or resolving issues with applications that rely on Java.
How to Locate the Java Version in Linux
Linux provides multiple ways to find the version of Java that is being installed on your system. These methods are simple and work across popular distributions such as CentOS, Fedora, etc. Whether you need to check the JDK version or the JRE version, the steps below will help. Let’s explore how to verify the version of Java on Linux using various approaches.
Method 1: Check the Java Version On Linux
Step 1: Open the Terminal
The first step to checking the Java version on Linux is to access the terminal. You are capable of finding this by:
- Browsing for “Terminal” in the menu of your applications.
- Using the keyboard shortcut Ctrl + Alt + T on most distributions.
- On remote systems, access the terminal through SSH (e.g., using ssh user@hostname).
Step 2: Run the Command
Once the terminal is open, execute the given below command to check the Java version that has been installed:
java -version
This command works universally on most Linux incorporating, Ubuntu, CentOS, & rest.
Step 3: Interpret the Output
After running the command, the output will provide the following details:
- Java Version Number: This indicates the exact version of Java installed.
- Build Details: Information about the build version and update level.
- Java Virtual Machine (JVM) Information: It specifies the JVM type (e.g., Java HotSpot).
For instance, the output might seem as:
java version "1.8.0_281"
Java(TM) SE Runtime Environment (build 1.8.0_281-b09)
Java HotSpot(TM) 64-Bit Server VM (build 25.281-b09, mixed mode)
- In this example:
- The Java version is 1.8.0_281, which corresponds to Java 8, update 281.
- The build version is b09.
- The system is using the Java HotSpot 64-Bit Server VM in “mixed mode,” allowing both interpreted and compiled execution.
Step 4: Handling Errors
If Java is not installed, you may encounter an error like:
Command ‘java’ not found
In such cases:
Confirm that Java is installed using package management commands (e.g., dpkg –list | grep java for Ubuntu or yum list installed | grep java for CentOS).
If Java is not installed, you can readily install it employing the appropriate package manager. For example:
sudo apt install default-jre # For Ubuntu
sudo yum install java-1.8.0-openjdk # For CentOS
Note:
- This method displays the default Java version configured on your system. If multiple versions are installed, you may need to check alternatives (explained in other methods).
- For systems where java is managed by symbolic links, the version returned by java -version might be the one currently active, not necessarily the only one installed.
Method 2: Find Version by Checking Path Where Java is Installed
Step 1: Locate the Java Path
If you want to check the Java version using the installation path, the first step is to find where Java is installed on your system. You can employ the which command to site the go-to way to the Java binary:
which java
- This command returns the location of the java executable file on your system.
Example output:
/usr/bin/java
- This indicates that Java is installed in the /usr/bin/ directory. The which command is helpful for locating the default Java binary, especially when there are multiple Java installations on your system.
Step 2: Run the Version Check Command
Once you have the path to the Java executable, you can run the version check command using the full path:
/usr/bin/java -version
- Replace /usr/bin/java with the actual path returned by the which command, if different.
- This will display the Java version tied to that specific path.
Step 3: Interpret the Output
The output will show details about the Java version installed at the specified path. For example, the output may look like:
java version "11.0.12" 2021-07-20 LTS
Java(TM) SE Runtime Environment (build 11.0.12+7-LTS)
Java HotSpot(TM) 64-Bit Server VM (build 11.0.12+7-LTS, mixed mode)
- Java Version: This shows the installed Java version (in this case, Java 11).
- Build Details: The build version (e.g., 11.0.12+7-LTS) provides additional context, such as the update level and LTS (Long Term Support) status.
- JVM Information: Indicates the Java Virtual Machine type (e.g., HotSpot) and its architecture (64-bit).
Method 3: Search for Java in the Installed Packages List
Step 1: List Installed Packages
To check the Java version via installed packages, you can list all installed packages that include “java” in their names. This approach is specifically helpful for seeing several Java versions that are being installed on your system, especially in environments that need different Java versions for different applications.
On Debian-based systems (e.g., Ubuntu), you can use the following command to list installed Java packages:
dpkg --list | grep -i java
The dpkg command lists all installed packages, and the grep -i java filters the results to show only those packages that contain “java” in their name, making it easy to identify Java-related packages.
Example output on Ubuntu:
openjdk-11-jdk 11.0.12+7-0ubuntu2
openjdk-8-jre 8u281-b09-0ubuntu1
- This shows that OpenJDK 11 and OpenJDK 8 are installed.
On Red Hat-based systems (e.g., CentOS, Fedora), use the following commands to achieve the same result:
yum list installed | grep java
The yum package manager lists all installed packages, and grep java filters out non-Java packages.
Further, you can employ the rpm command to list packages:
rpm -qa | grep java
Example output on CentOS:
java-1.8.0-openjdk-1.8.0.312.b07-1.el7_9.x86_64
- This shows the installed version of OpenJDK 8 for CentOS.
Step 2: Find Relevant Entries
After running the package listing command, look for Java-related package entries. The relevant entries will typically be package names like openjdk or oracle-java, depending on the Java distribution installed.
- For example, package names like:
- openjdk-11-jdk: Indicates that OpenJDK 11 is installed.
- openjdk-8-jre: Indicates that OpenJDK 8 JRE is installed.
- oracle-java-8: Refers to Oracle JDK 8, if Oracle’s JDK version is installed.
Step 3: Check Package Versions
The package listing will include both the package name as well as its version no. This helps you confirm which version of Java is installed.
- For instance:
Ubuntu:
openjdk-11-jdk 11.0.12+7-0ubuntu2
openjdk-8-jre 8u281-b09-0ubuntu1
Here, OpenJDK 11 and OpenJDK 8 are installed, with versions clearly indicated.
CentOS:
java-1.8.0-openjdk-1.8.0.312.b07-1.el7_9.x86_64
This shows OpenJDK 8 version 1.8.0_312.
Also Read: How to Install Java on MacOS?
Final Words
Understanding how to verify the Java version in Linux ensures your system runs efficiently and stays compatible with modern applications. Whether you need to verify the JDK version in Linux, locate specific installations, or ensure software requirements are met, the methods in this guide will help.
At Hostbillo, we understand how critical a well-configured environment is for your projects. Our premium hosting services are tailored for developers and businesses, offering robust support for Java-based applications. With our high-performance servers, you can deploy applications seamlessly while focusing on development, not system compatibility.
Choose Hostbillo’s hosting solutions for reliable, scalable, and secure services. Optimize your Java applications and get expert support for all your hosting needs. Whether you’re a beginner or a pro, Hostbillo ensures your infrastructure supports your vision.