How to check Java Version Installed on Linux

Configurare noua (How To)

Situatie

Java is one of the most popular, multi-platform, network-centric programming languages used for creating cross-platform applications for businesses.

The installed version of Java on a system plays a critical role in supporting specific Java features. In addition, sysadmins and DevOps professionals need to know the Java version to deploy compatible software and web services, maintain a secure system, improve performance, and troubleshoot Java applications effectively.

Solutie

Understanding the Java Version Format

Java adheres to semantic versioning format, designed to highlight releases, updates, and patches within the Java ecosystem. The key components include major, minor, update, build, and patch information.

For instance, Java 11.0.8 has three versions: a security version, a minor version, and a major version of 11.

MAJOR – New features and functions are included in major releases.

MINOR – Minor updates include several compatible bug fixes.

SECURITY – Critical security fixes are included in security releases.

Before we move on, ensure you have the following:

  • A system running a mainstream Linux distro
  • A user account with root or sudo permissions
  • Javais  installed on your system

Method #1: Using the Java Version Command

Launch the terminal and run the following command:

# java -version

The terminal displays the installed Java version. The output typically includes the version number, update version, and other details specific to the Java Runtime Environment (JRE) or Java Development Kit (JDK) installed on your system.

For instance, you can see that the command shows that we have OpenJDK (Open Java Development Kit) version 11 (build 11.0.2247) on our system.

You can check the version of the Java compiler (javac) with the following command:

# javac -version

Method #2: Discover Version Through the Java Installation Path

This method involves finding the directory where Java is installed on your system and determining the version from the directory name.

Run the following command in the terminal to find out the Java installation path on the system:

update-alternatives --list java

If you have multiple Java versions, the command will show the paths for all versions.

Alternatively, use the whereis command to locate the Java directory:

# whereis java

This command displays a path (usually, /usr/bin/java). You can then list the contents of this directory to follow the symbolic links to the actual Java installation path:

# ls -l /usr/bin/java

Following the symbolic links (using ls -l again if necessary) will eventually lead you to the real Java installation directory, for example, /usr/lib/jvm/java-11-openjdk-amd64/bin/java.

Method #3: List Installed Java Packages

Another method to find Java version is by leveraging the Linux distribution’s package manager to list the installed packages:

Start by generating a list of installed packages with the following command:

sudo apt list --installed

The output can be pretty detailed on a typical system. We recommend pipping it through grep to find Java packages:

# sudo apt list --installed | grep -i openjdk

The output of this command lists out all OpenJDK packages installed on the system. For instance, a package named openjdk-17-jdk likely indicates Java version 17.

Tip solutie

Permanent

Voteaza

(2 din 4 persoane apreciaza acest articol)

Despre Autor

Leave A Comment?