How to Find the Java Version in Linux

Sun Microsystems created Java in 1995 as a high-level, object-oriented programming language. Java has developed into one of the most well-known high-level languages over time. Nowadays, it is well-liked by businesses in the financial, scientific, and real estate sectors. It is open-source, platform-independent, adaptable, and simple to understand and use.

One of the most well-liked programming languages used to create various cross-platform applications is called Java. The majority of what is possible in Python is also possible in Java. Additionally, Jpython is a version of Python that works with Java and the JVM (Java Virtual Machine). This article will walk you through finding the latest Java version for Ubuntu Linux and installing it if it isn't already installed.

How to use the command line to determine what version of Java is installed on your Linux system is described in this article. When setting up software that needs a particular Java version, this can be helpful.

What is Java Version?

The Java version specifies the Java software release that your OS is currently using.

For improved performance, stability, complex features, and the most recent security updates, it is strongly advised that the version should be updated. This can go a long way toward assisting you in staying current and helping you avoid many undesired problems.

You must upgrade to the most recent Java version in order to use many websites, packages, or libraries. It is therefore preferable to stay current and have the most recent release downloaded on your PC. For instance, the most recent Java version offers intriguing capabilities like the ability to examine 3D images.

Let's get started with the process of installing and verifying the Java version without further ado.

Verifying the Java Version

Semantic versioning is used by Java. Releases that are ready for production are versioned as follows:

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 a number of compatible bug fixes.

SECURITY - Critical security fixes are included in security releases.

In General, follow below two steps to Verify Java Version in your System:

  1. Open Command Prompt.
  2. Use the java -version command to determine the Java version that is currently installed on your system:

Java version verification for Linux Ubuntu, Debian, and CentOS

Follow below Steps:

  1. Launch the terminal.
  2. Execute the next command:

In this example, our machine is running Java version 19.0.1. It's possible that the version on your PC is different.

If you receive the error message "java: command not found," Java is not installed on the computer. Depending on your Linux distribution, use one of the following instructions to install Java.

There are ways to install packages in the terminal. You should be able to install the version straight through the terminal by copying these commands and running them. Since none of these versions require a graphical user interface, they are all "headless."

However, you can utilize the browser technique to obtain the most recent version (16.02). Let's now walk through the installation process step by step.

Installing Java Using the Browser

Observe the instructions to download Java.

  • Go to Google, type in "download java JDK," and click the first link that appears.
  • The "Java Development Kit" (JDK) is a tool used to create Java-based software. Alternatively, you can access the page right away by clicking this link.
  • Go to "Java SE 16" under "Java SE downloads," as that is the most recent version. Downloading JDK is the following procedure.
  • Find the "Linux x64 Debian Package" by scrolling through the packages. Download the document that's there. You'll see that the file has deb extension since Ubuntu installs programs using Debian packages.
  • Open the folder containing the downloaded package once the download is complete. Choose "Open in Terminal" by performing a right-click anywhere in the window.
  • To begin unpacking the downloaded package, enter the following command into the terminal.

Using the Java Installation Path, check the version of Java:

The Java installation path can be used to check the Java version as well.

There are two ways to locate the Java installation path or directory.

  • The following command can be used as the initial approach to locate the Java installation path:

This will reveal the entire Java path, as illustrated below:

Note: Run the following command to access the CentOS and RHEL operating systems:

  • The whereis command can also be used to look for the Java path.

Use the whereis command as demonstrated below:

Output: The output should be as follows:

java: /usr/bin/java /usr/share/java /usr/share/man/man1/java.1.gz

Following that, use the ls command to list what is in /usr/bin/java:

you ought to observe the following result:

lrwxrwxrwx 1 root root 22 Feb 5 04:50 /usr/bin/java -> /etc/alternatives/java

As you can see from the output above, /usr/bin/java is a symbolic link to /etc/alternatives/java.

In order to list the contents of /etc/alternatives/java, use the ls command once more.

It will display the path.

Search for Java Version in the Installed Package List:

To view a list of installed packages and perform a Java search, you may also check the Java version. Follow the instructions below for the Ubuntu and Debian operating systems:

You may list all installed packages using the apt or dpkg commands.

1. Using the apt command, list all installed packages and look for Java:

The following output ought to show the Java version that was installed:

openjdk-11-jdk-headless/focal-updates,focal-security,now 11.0.9.1+1-0ubuntu1~20.04 amd64 [installed,automatic]
openjdk-11-jdk/focal-updates,focal-security,now 11.0.9.1+1-0ubuntu1~20.04 amd64 [installed,automatic]
openjdk-11-jre-headless/focal-updates,focal-security,now 11.0.9.1+1-0ubuntu1~20.04 amd64 [installed,automatic]
openjdk-11-jre/focal-updates,focal-security,now 11.0.9.1+1-0ubuntu1~20.04 amd64 [installed,automatic]

2. Using the dpkg command, list all installed packages and look for Java:

The following output ought to show the Java version that was installed:

/usr/lib/jvm/java-11-openjdk-amd64/bin/java      1111      auto mode
/usr/lib/jvm/java-11-openjdk-amd64/bin/java      1111      manual mode
/usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java   1081      manual mode

Follow the instructions below for the CentOS and RHEL operating systems:

To list all installed packages and look for Java, use the yum or dnf commands as shown below:

This will reveal the installed Java version as displayed below:

java-11-openjdk.x86_64               1:11.0.9.11-3.el8_3                     
java-11-openjdk-devel.x86_64         1:11.0.9.11-3.el8_3                   
java-11-openjdk-headless.x86_64      1:11.0.9.11-3.el8_3   

Get rid of Java versions

You can enter the following command to remove Java from your computer:

If we want to remove the package then we can enter the command:

The package will be removed if you press "Y" and then "ENTER."

Will it possible in jdk or jre?

JRE is required to run Java apps (Java runtime environment). It works with several operating systems, including Windows, Linux, Mac, and Solaris.

Java programmes are developed using the JDK (Java Development Kit). The majority of programmers often start there. Depending on what you want to accomplish.

Utilizing JDK(when…?)

You wish to create Java applications. A compiler and Java application launcher are included.

It has access to the primary Java libraries through the Java application launcher, which launches JRE, for coding.

JRE When to use

Libraries and other files must be used. It lacks its own compiler and fault detection software. when using utility programmes such as math or data-related sets and instructions to run Java-based apps.

Some Java Applications

Java is mostly used for

  • creating applications for Android.
  • when creating cloud-based and web applications.
  • such as Netbeans and the Eclipse software.
  • Chatbots.
  • Games.
  • Enterprise and scientific applications

Simply execute java -version to quickly see what Java version is installed on your Linux system.

Keeping our programmes updated is essential if we want to stay update and receive hands-on experience with the newest software and packages. This check and balance can go a long way toward ensuring that our system is effective, secure, and current.

Once the Java version is known, you may begin creating anything from simple desktop programmes to mobile ones.