How to Check Java Version Installed on Linux
Java remains an essential component in the Linux ecosystem, powering enterprise applications, web services, and development environments. Whether you’re a system administrator, developer, or Linux enthusiast, knowing which Java version runs on your system is crucial for compatibility, security, and troubleshooting. This comprehensive guide explores multiple methods to check Java versions on Linux systems and understand the information presented.
Why Checking Java Version is Important
Understanding your current Java installation isn’t merely a technical exercise—it directly impacts your system’s functionality and security in several ways.
Security Considerations
Java installations receive regular security updates to patch vulnerabilities. Outdated versions may contain known security flaws that malicious actors actively exploit. By regularly checking your Java version, you can ensure you’re running a release with the latest security patches, protecting your system from potential threats.
Compatibility Requirements
Many applications specify minimum Java version requirements or are designed for specific Java releases. Some enterprise software might require Java 8 for stability, while newer applications may need features only available in Java 11 or 17. Without knowing your current Java version, you risk encountering mysterious compatibility issues and errors that can be difficult to diagnose.
Performance Improvements
Each Java release brings performance optimizations that can significantly impact application responsiveness and resource utilization. Java 9 introduced a more efficient garbage collector, while Java 10 brought application class-data sharing to improve startup times. Staying informed about your Java version helps you leverage these improvements.
Effective Troubleshooting
When encountering Java-related issues, version information serves as critical diagnostic data. Many Java errors stem from version mismatches between components or libraries, and support teams typically request this information first when addressing problems.
Development Environment Consistency
For developers, maintaining consistent Java versions across development, testing, and production environments prevents the frustrating “works on my machine” syndrome. Regular version checking helps ensure this consistency throughout the development pipeline.
Prerequisites
Before exploring the various version-checking methods, ensure you have:
Basic Command Line Knowledge
You’ll need fundamental familiarity with Linux terminal commands—navigating directories, executing commands, and interpreting outputs. Most methods in this guide require only basic terminal operations.
Terminal Access
All techniques require terminal access to your Linux system. Access the terminal through your desktop environment’s application menu or by pressing key combinations like Ctrl+Alt+T on many distributions.
Understanding Java Distributions
Java comes in different flavors on Linux systems:
- OpenJDK: The open-source reference implementation, most commonly packaged in Linux distributions
- Oracle JDK: The proprietary implementation with additional features and commercial support
- IBM Java: Optimized for IBM systems
- Amazon Corretto: Amazon’s distribution with long-term support
JRE vs. JDK Distinction
It’s important to understand the difference between:
- Java Runtime Environment (JRE): Contains everything needed to run Java applications
- Java Development Kit (JDK): Includes the JRE plus development tools for Java programming
The version-checking methods may reveal which component you have installed, as they report slightly different information.
Method 1: Using the java -version Command
The most direct and universal approach to check Java on any Linux distribution is the java -version
command.
Step-by-step Instructions
- Open your terminal application
- Type the following command and press Enter:
java -version
- Review the displayed output
This simple command queries the default Java runtime and displays detailed version information.
Understanding the Output
A typical output might appear as:
openjdk version "11.0.14" 2022-01-18
OpenJDK Runtime Environment (build 11.0.14+9-Ubuntu-0ubuntu2.20.04)
OpenJDK 64-Bit Server VM (build 11.0.14+9-Ubuntu-0ubuntu2.20.04, mixed mode, sharing)
This output provides several key pieces of information:
- First line: Shows the Java distribution (OpenJDK) and major version (11.0.14)
- Second line: Contains runtime environment details and build information
- Third line: Provides JVM implementation details, architecture (64-bit), and operating mode
Examples from Different Java Distributions
Oracle JDK might display:
java version "1.8.0_301"
Java(TM) SE Runtime Environment (build 1.8.0_301-b09)
Java HotSpot(TM) 64-Bit Server VM (build 25.301-b09, mixed mode)
Amazon Corretto might show:
openjdk version "11.0.14.1" 2022-02-08 LTS
OpenJDK Runtime Environment Corretto-11.0.14.10.1 (build 11.0.14.1+10-LTS)
OpenJDK 64-Bit Server VM Corretto-11.0.14.10.1 (build 11.0.14.1+10-LTS, mixed mode)
Troubleshooting Command Not Found
If you receive a “command not found” error, it indicates that:
- Java is not installed on your system
- Java is installed but not in your system’s PATH
- Your distribution requires different package names
To resolve this issue:
- Install Java using your distribution’s package manager (e.g.,
sudo apt install default-jre
for Debian/Ubuntu) - Check your PATH variable with
echo $PATH
to verify Java’s location is included - Use
which java
to locate the Java binary if it exists
Using java -fullversion
For more detailed version information, especially useful in scripts, use:
java -fullversion
This produces a single line output containing the full version string, making it easier to parse programmatically.
Method 2: Checking Java Compiler Version
While runtime verification is common, developers often need to verify their compiler version for development tasks.
Using javac -version
To check the Java compiler version, execute:
javac -version
This command returns the version of the Java compiler (javac) installed on your system.
Why Check Compiler Version
The compiler version matters particularly for developers because:
- It determines which language features are available for your code
- It affects compatibility with libraries and frameworks
- It ensures your build environment matches your runtime environment
Sample Output
A typical output appears simply as:
javac 11.0.14
Unlike the runtime output, this format is concise, showing only the compiler version without additional build information.
When Compiler and Runtime Versions Differ
In some scenarios, particularly in development environments, you might have mismatched compiler and runtime versions. This situation can arise when:
- You’ve installed multiple JDK versions and configured them differently
- Your system uses one Java version by default but your IDE references another
- You’ve updated your JRE but not your JDK, or vice versa
Such mismatches can lead to compatibility issues where code compiles successfully but fails at runtime.
Method 3: Using update-alternatives
Linux distributions using the alternatives system (like Debian, Ubuntu, Fedora, and CentOS) offer powerful management capabilities for multiple Java installations.
Command Syntax for Listing Java Alternatives
To list all installed Java installations registered in the alternatives system:
update-alternatives --list java
This shows all Java versions managed by your system’s alternatives mechanism.
Purpose and Benefits
The alternatives system allows you to:
- Maintain multiple Java versions concurrently
- Switch between different versions system-wide
- Configure default versions for specific Java components
- Track manually installed Java versions
Output Interpretation
A typical output might appear as:
/usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java
/usr/lib/jvm/java-11-openjdk-amd64/bin/java
/usr/lib/jvm/java-17-openjdk-amd64/bin/java
Each line represents a distinct Java installation with its full path, revealing:
- Available Java versions (8, 11, and 17 in this example)
- Distribution type (OpenJDK)
- System architecture (amd64)
- Exact location of each Java binary
Checking All Java-related Alternatives
For a complete picture of your Java environment, check alternatives for other components:
update-alternatives --list javac # Java compiler
update-alternatives --list jar # Java archive tool
update-alternatives --list javadoc # Java documentation generator
Switching Between Java Versions
To change your default Java version:
sudo update-alternatives --config java
This interactive command presents available Java versions, allowing you to select which one should be the system default.
Method 4: Finding Java in Installed Packages
Package managers maintain detailed records of installed software, providing another source of information about your Java installations.
Using Package Managers
Different Linux distributions use different package managers:
- Debian/Ubuntu: apt
- Fedora: dnf
- CentOS/RHEL: yum or dnf
- Arch Linux: pacman
Commands for Different Package Managers
For Debian/Ubuntu systems:
apt list --installed | grep -i 'java\|openjdk\|oracle'
For Fedora or modern CentOS:
dnf list installed | grep -i 'java\|openjdk\|oracle'
For older CentOS/RHEL systems:
yum list installed | grep -i 'java\|openjdk\|oracle'
Filtering and Understanding Results
Focus on packages with names containing:
openjdk
: Open Java Development Kitjava
: General Java-related packagesjre
: Java Runtime Environment componentsjdk
: Java Development Kit components
Package Naming Conventions
Package names typically include version information, though formats vary by distribution:
- Debian/Ubuntu:
openjdk-11-jre
indicates OpenJDK version 11, JRE component - Fedora/CentOS:
java-11-openjdk
indicates OpenJDK version 11 - Version numbers might appear as
1.8.0
(Java 8) or directly as11
(Java 11)
Distribution-specific Differences
Be aware that distributions package Java differently:
- Ubuntu typically separates JRE and JDK into distinct packages
- Some distributions bundle debugging tools separately
- Enterprise distributions might include additional security patches
- Default versions vary significantly between distributions
Method 5: Locating Java Installation Path
Understanding exactly where Java resides on your filesystem helps with troubleshooting and configuration.
Using which java
To find the location of your Java executable:
which java
This returns the path to the Java binary that executes when you type java
at the command line.
Following Symbolic Links
On most Linux systems, the path returned by which java
is actually a symbolic link. To find the actual binary:
ls -l $(which java)
You might see output like:
lrwxrwxrwx 1 root root 22 Feb 10 09:14 /usr/bin/java -> /etc/alternatives/java
To follow the complete chain:
ls -l /etc/alternatives/java
Which might show:
lrwxrwxrwx 1 root root 43 Feb 10 09:14 /etc/alternatives/java -> /usr/lib/jvm/java-11-openjdk-amd64/bin/java
Complete Path Resolution
To resolve the complete path in one command:
readlink -f $(which java)
This follows all symbolic links and returns the absolute path to the actual Java binary.
Checking JAVA_HOME Environment Variable
Many applications rely on the JAVA_HOME
environment variable:
echo $JAVA_HOME
If this returns a value, it indicates the Java installation directory used by applications that depend on this variable.
Manual Path Exploration
Once you’ve found the Java binary location, explore the surrounding directory structure:
# Find the Java installation root
cd "$(dirname "$(readlink -f "$(which java)")")/.."
pwd
ls -la
This typically reveals the root of your Java installation with directories like:
bin/
: Executable toolslib/
: Libraries and resourcesinclude/
: Header files for native codejre/
: (In older JDK installations) The runtime environment
Understanding Java Version Output
The output from java -version
contains valuable information beyond just the version number.
Version Number Format
Java version numbers follow specific patterns:
- Legacy format (Java 8 and earlier):
1.8.0_301
1
is the major version (always 1 for older versions)8
is the feature release number0
is the maintenance release number_301
is the update number
- Modern format (Java 9 and later):
11.0.14
11
is the feature release number0
is the interim release number14
is the update release number
Build Information
The build string provides details about when and how the Java release was created:
(build 11.0.14+9-Ubuntu-0ubuntu2.20.04)
In this example:
11.0.14
is the version number+9
is the build numberUbuntu-0ubuntu2.20.04
indicates distribution-specific modifications
JVM Details
The JVM line contains information about the Java Virtual Machine implementation:
OpenJDK 64-Bit Server VM (build 11.0.14+9-Ubuntu-0ubuntu2.20.04, mixed mode, sharing)
Key components include:
- JVM implementation (OpenJDK 64-Bit Server VM)
- Architecture (64-Bit)
- Operating mode (Server VM)
- Execution mode (mixed mode)
- Class data sharing setting (sharing)
Distribution Identifiers
Different Java distributions identify themselves uniquely:
- OpenJDK: Shows “openjdk version”
- Oracle: Shows “java version” with Java(TM) branding
- IBM: Includes “IBM” in the version string
- Amazon Corretto: Includes “Corretto” in the build information
Release Date Information
Some Java versions include the release date in the version output:
openjdk version "11.0.14.1" 2022-02-08 LTS
Here, “2022-02-08” indicates the release date, and “LTS” designates a Long-Term Support release.
Managing Multiple Java Versions
As your Java needs evolve, you’ll likely need to manage multiple Java versions on a single Linux system.
Common Scenarios for Multiple Versions
Several situations require multiple Java installations:
- Supporting legacy applications needing older Java versions
- Developing applications targeting different Java platforms
- Testing compatibility across Java versions
- Using version-specific features while maintaining backward compatibility
Using the Alternatives System
The alternatives system provides a consistent way to manage multiple Java versions:
# Set the default Java version
sudo update-alternatives --config java
# Set the default Java compiler
sudo update-alternatives --config javac
For manual installation, register a new Java version:
sudo update-alternatives --install /usr/bin/java java /path/to/new/java/bin/java 100
The number (100) represents the priority—higher numbers take precedence in automatic selection.
Environment Variables for Temporary Switching
For temporary or user-specific Java selection:
# Set a specific Java version for the current session
export JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64
export PATH=$JAVA_HOME/bin:$PATH
# Verify the change
java -version
This affects only the current terminal session without changing system-wide settings.
Application-Specific Configurations
Many applications allow specifying which Java version to use:
- Tomcat: Set
JAVA_HOME
insetenv.sh
- Maven: Configure
JAVA_HOME
in~/.mavenrc
- Gradle: Use the
org.gradle.java.home
property - IntelliJ IDEA: Set the project SDK in Project Structure settings
Best Practices for Version Management
To maintain a clean and manageable Java environment:
- Use your distribution’s package manager when possible
- Document installed versions and their purposes
- Regularly audit and remove unused Java installations
- Consider version managers like
jenv
orjabba
for complex setups
Checking Java in Web Browsers
While browser-based Java has been largely deprecated, some legacy applications still use it.
Browser Plugins vs. System Java
Browser Java implementations are separate from your system’s Java installation:
- They run in sandboxed environments
- Have their own update mechanisms
- May have different security settings
- Are version-controlled independently
Browser-Specific Version Checking
Modern browsers have either removed or restricted Java plugin support:
- Firefox: Type
about:plugins
in the address bar (older versions) - Chrome: Type
chrome://plugins
(older versions before plugin removal) - Edge: Does not support Java plugins
For browsers that still support Java, visit https://www.java.com/verify/
to check the plugin version.
Security Considerations
Browser-based Java poses significant security risks:
- Java applets can request elevated permissions
- Outdated browser plugins are common attack vectors
- Modern browsers block Java content by default
- Oracle has deprecated the Java browser plugin
Modern Alternatives
Instead of Java applets, modern web applications use:
- WebAssembly for near-native performance
- JavaScript frameworks for rich client-side functionality
- HTML5 technologies that replace former Java plugin features
Troubleshooting Common Issues
Even experienced Linux users occasionally encounter Java-related problems.
No Java Found
If java -version
returns “command not found”:
- Install Java using your distribution’s package manager:
# Ubuntu/Debian
sudo apt update
sudo apt install default-jre
# Fedora
sudo dnf install java-latest-openjdk
# CentOS
sudo yum install java-11-openjdk
- Verify successful installation:
java -version
Path and Environment Variable Problems
If Java is installed but not found or the wrong version runs:
- Check your PATH variable:
echo $PATH
- Verify JAVA_HOME is correctly set:
echo $JAVA_HOME
- Add Java to your PATH temporarily:
export PATH=/usr/lib/jvm/your-java-version/bin:$PATH
- Add to
.bashrc
for persistence:
echo 'export JAVA_HOME=/usr/lib/jvm/your-java-version' >> ~/.bashrc
echo 'export PATH=$JAVA_HOME/bin:$PATH' >> ~/.bashrc
source ~/.bashrc
Permission Issues
Java executables might have incorrect permissions:
- Check file permissions:
ls -l $(which java)
- Fix if necessary:
sudo chmod +x $(which java)
Conflicting Versions
When multiple Java versions conflict:
- List all installed versions:
update-alternatives --list java
- Select the appropriate default:
sudo update-alternatives --config java
- Remove unwanted versions if necessary:
sudo apt remove openjdk-8-jre # Example for Ubuntu
Broken Installations
For corrupted Java installations:
- Purge and reinstall:
# Ubuntu/Debian
sudo apt purge openjdk*
sudo apt autoremove
sudo apt install default-jre
- Check for orphaned configurations:
sudo update-alternatives --remove-all java