How to Check Java Version

By 

•

Updated on

•

6 min read

Check Java Version

Before installing an application that runs on Java, such as Tomcat, Jenkins, or Maven, you need to know whether Java is installed on your system and which version it is. Many applications require a specific minimum version and refuse to start with older releases.

This guide explains how to check the installed Java version from the Linux command line, verify the JDK compiler, and find out which installation is the default when multiple versions are present.

Checking the Java Runtime Version

To find out which Java version is installed on your system, run the java -version command:

Terminal
java -version

The command prints the default Java runtime version:

output
openjdk version "25.0.4.1" 2026-08-18
OpenJDK Runtime Environment (build 25.0.4.1+1-1-26.04.4-Ubuntu)
OpenJDK 64-Bit Server VM (build 25.0.4.1+1-1-26.04.4-Ubuntu, mixed mode, sharing)

In this example, Java version 25.0.4.1 is installed. This is the default OpenJDK release on Ubuntu 26.04. The version on your system may differ depending on which package you installed.

Java 9 and newer also accept java --version (with two dashes), which prints the same information to standard output instead of standard error. This distinction matters when you pipe the output to another command.

The first line of the output is formatted a little differently. It drops the word “version” and the quotes around the number:

Terminal
java --version
output
openjdk 25.0.4.1 2026-08-18
OpenJDK Runtime Environment (build 25.0.4.1+1-1-26.04.4-Ubuntu)
OpenJDK 64-Bit Server VM (build 25.0.4.1+1-1-26.04.4-Ubuntu, mixed mode, sharing)

If you get “java: command not found”, it means that Java is not installed on the system. On Ubuntu, the shell prints Command 'java' not found, but can be installed with: followed by a list of OpenJDK packages. To install Java, use one of the following guides depending on your Linux distribution:

Understanding Java Version Numbers

Since JDK 10, Java version numbers follow the scheme defined in JEP 322:

txt
FEATURE.INTERIM.UPDATE.PATCH

For example, in Java 25.0.4.1, 25 is the feature release, 0 is the interim release, 4 is the update release, and 1 is the patch release. Trailing components with a value of zero are omitted. A version such as 21.0.11 has no patch release, so it has only three numbers.

  • FEATURE - Increases every six months with each feature release that brings new language and platform features.
  • INTERIM - Reserved for releases between feature releases. In practice, it is always 0.
  • UPDATE - Increases with each quarterly update that delivers bug and security fixes.
  • PATCH - Increases only for emergency releases that fix critical issues. It is omitted when its value is zero.

Oracle publishes a new feature release every six months. Long-term support (LTS) releases, which receive updates for several years, come out every two years. Java 8, 11, 17, 21, and 25 are LTS releases.

Java 8 predates this scheme and uses the older 1.x format. On a Java 8 system, java -version prints a version string such as 1.8.0_492, where 8 is the release and 492 is the update number.

Checking the Java Compiler Version

The java command shows the runtime (JRE) version. If you need to compile Java code, you also need the Java Development Kit (JDK). To check whether the JDK is installed and which version it provides, run:

Terminal
javac -version

The output shows the compiler version:

output
javac 25.0.4.1

If the command is not found, the JDK may not be installed, or the directory containing javac may not be in your PATH. Install the JDK package to get the compiler. On Ubuntu and Debian, the package is named default-jdk or a version-specific package such as openjdk-25-jdk.

Listing Installed Java Versions

A system can have several Java versions installed side by side. To list all of them on Ubuntu, Debian, and derivatives, run:

Terminal
update-alternatives --list java

The command prints the full path of every registered Java executable:

output
/usr/lib/jvm/java-21-openjdk-amd64/bin/java
/usr/lib/jvm/java-25-openjdk-amd64/bin/java

In this example, two versions are installed: Java 21 and Java 25. You can also inspect the /usr/lib/jvm directory, where Linux distributions place Java installations. On Fedora, RHEL, and derivatives, use alternatives --display java instead.

Checking the JAVA_HOME Variable

Many Java applications and build tools such as Maven, Gradle, and Tomcat rely on the JAVA_HOME environment variable to locate the Java installation. To check whether it is set, run:

Terminal
echo $JAVA_HOME

If the variable is set, the output shows the installation path:

output
/usr/lib/jvm/java-25-openjdk-amd64

An empty output means JAVA_HOME is not configured. To find the location of the default Java installation, run:

Terminal
java -XshowSettings:properties -version 2>&1 | grep java.home
output
    java.home = /usr/lib/jvm/java-25-openjdk-amd64

The -XshowSettings:properties option prints the JVM system properties to standard error, and grep picks out the java.home line. When a build tool requires a JDK, set JAVA_HOME to the JDK root directory containing bin/javac. On Java 8, java.home points to the nested jre directory, so use its parent directory instead.

To set JAVA_HOME, add the following line to your ~/.bashrc or ~/.profile file:

sh
export JAVA_HOME=/usr/lib/jvm/java-25-openjdk-amd64

Replace the path with the actual location of your Java installation. You can also use one of the paths from the previous section, without the /bin/java suffix.

Managing Multiple Java Versions

When more than one Java version is installed, you can choose which one is the default. To switch between them, run:

Terminal
sudo update-alternatives --config java

The command displays a menu with every registered Java installation:

output
There are 2 choices for the alternative java (providing /usr/bin/java).

  Selection    Path                                         Priority   Status
------------------------------------------------------------
* 0            /usr/lib/jvm/java-25-openjdk-amd64/bin/java   2511      auto mode
  1            /usr/lib/jvm/java-21-openjdk-amd64/bin/java   2111      manual mode
  2            /usr/lib/jvm/java-25-openjdk-amd64/bin/java   2511      manual mode

Press <enter> to keep the current choice[*], or type selection number:

The asterisk marks the current default. In auto mode (selection 0), the system uses the version with the highest priority, in this case Java 25. On recent Ubuntu and Debian releases, the menu is shown even when only one version is installed, and the first line then reads “There is 1 choice”. Older releases may print “Nothing to configure” instead.

Enter the number from the Selection column and press Enter to change the default. This command is available on Debian-based distributions (Ubuntu, Debian, Linux Mint). On Fedora and RHEL-based systems, use alternatives --config java instead.

The java and javac commands are managed as separate alternatives. If you have more than one JDK installed, run sudo update-alternatives --config javac to switch the compiler as well.

FAQ

Does java -version show the JDK or the JRE?
It shows whichever runtime is set as the default. Both the JRE-only package and the full JDK include the java command. To confirm that the JDK is installed, check for javac as described above.

How do I check the Java version inside a shell script?
Parse the output of java -version, which prints to standard error:

Terminal
java -version 2>&1 | head -n 1 | awk -F '"' '{print $2}'

This returns a string such as 25.0.4.1. The awk pattern splits the line on the double quotes, so use -version here. The --version output has no quotes around the number.

Do not compare Java versions as ordinary strings because values such as 9 and 17 sort incorrectly. Use a version-aware comparison such as sort -V when your script needs to enforce a minimum version.

Conclusion

Use java -version to check the installed runtime and javac -version to verify the JDK. If you need to manage multiple versions, our update-alternatives guide explains how to inspect, switch, and automate the default selection.

Tags

Linuxize Weekly Newsletter

A quick weekly roundup of new tutorials, news, and tips.

About the authors

Dejan Panovski

Dejan Panovski

Dejan Panovski is the founder of Linuxize, an RHCSA-certified Linux system administrator and DevOps engineer based in Skopje, Macedonia. Author of 1000+ Linux tutorials with 20+ years of experience turning complex Linux tasks into clear, reliable guides.

View author page