Java is a high-level, Object-Oriented programming language developed in 1995 by Sun Microsystems. Over time, Java has grown to become one of the most prominent high-level languages. It is now popular among app developers, financial, scientific, and estate enterprises. It is independent of the platform, open-source, versatile, and easy to learn and use.

It is practically a Turing-complete language so anything can be done on it. Most of the things one can do in Python can also be done in Java. Jpython is a Python version that runs on Java in the JVM (Java Virtual Machine). In this guide, we will dive into the procedure of looking up the Java version on Ubuntu Linux and install it if it is not already available.

Understanding the Java Version

The Java version is an indicator of the release of Java software currently under use by your OS.

It is highly recommended that the version be updated for better performance, stability, sophisticated features, and the latest security patches. This can go a long way and help you in preventing many unwanted issues and staying up to date.

Many websites, packages, or libraries require you to update to the latest Java version. So, it is preferred to stay one step ahead and have the latest release downloaded on your system. For instance, the latest Java version enables you to view 3D images along with other exciting features.

So, without further ado, let’s delve into the procedure of Java version verification and installation.

Checking Your Java Version

Start by checking your Java version. To do this, simply type the following in the terminal window.

Or

This will give us the Java version that’s currently in use.

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/09/echo/1-2.jpg" data-lazy- height="603" src="data:image/svg xml,” width=”1065″>

However, as evident from the picture above, Java isn’t installed on our system. But the terminal gives us options to install packages. Copying these commands and running them should get you the version installed directly via the terminal. All these versions are “headless”, meaning they don’t require a graphical user interface.

However, to download the latest release (16.02), you can use the browser method. Now, let’s go through the step-by-step process of installation.

Installing Java Using the Browser

Follow the steps to download Java.

Go to Google and search “download java JDK” and open the first link from the search results.

JDK is the “Java Development Kit” used to develop programs that run on Java. Alternatively, you can click on the link here to go directly to the page.

Under the “Java SE downloads”, go to “Java SE 16” as that is the latest version. The next step is to download JDK.

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/09/echo/2-2.jpg" data-lazy- height="786" src="data:image/svg xml,” width=”1099″>

Scroll through the packages till you find the “Linux x64 Debian Package”. Download the file next to it. Ubuntu uses Debian packages to install programs, so you’ll see that the file has a .deb extension.

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/09/echo/3-2.jpg" data-lazy- height="769" src="data:image/svg xml,” width=”1072″>

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/09/echo/4-2.jpg" data-lazy- height="709" src="data:image/svg xml,” width=”1075″>

Once you are done with the download, open the folder where the downloaded package is located. Right-click anywhere in the window and select “Open in Terminal”.

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/09/echo/5-2.jpg" data-lazy- height="809" src="data:image/svg xml,” width=”1095″>

Type the following command in the terminal to start unpacking the downloaded package.

$ sudo dpkg –i jdk-16.0.2_linux-x64_bin.deb

You can replace the highlighted part of the command with the name of the package corresponding to the Java version you downloaded.

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/09/echo/6-2.jpg" data-lazy- height="797" src="data:image/svg xml,” width=”1093″>

Having done that, you can type in the following command to confirm that Java is installed on your system.

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/09/echo/7-2.jpg" data-lazy- height="131" src="data:image/svg xml,” width=”1052″>

With that out of the way, set your package as the alternative. To do that, use the following command:

$ sudo update-alternatives –install /usr/bin/java java /usr/lib/jvm/jdk-16.0.2/bin/java 1

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/09/echo/8-1.jpg" data-lazy- height="140" src="data:image/svg xml,” width=”1081″>

Now, we can finally check and verify our version by typing the following:

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/09/echo/9-1.jpg" data-lazy- height="141" src="data:image/svg xml,” width=”1079″>

To install the compiler, just use the same command as before, only this time replace “java” with “javac”.

$ sudo update-alternatives –install /usr/bin/javac javac /usr/lib/jvm/jdk-16.0.2/bin/javac 1

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/09/echo/10.jpg" data-lazy- height="355" src="data:image/svg xml,” width=”1082″>

To check the Javac version, type the following command:

Additionally, to set the java_home path, enter the following:

$ sudo update-a;ternatives –config java

$ sudo gedit /etc/environment

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/09/echo/11.jpg" data-lazy- height="305" src="data:image/svg xml,” width=”1080″>

Once the text editor opens, paste the copied line and assign it to “JAVA_HOME” as demonstrated below.

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/09/echo/12.jpg" data-lazy- height="898" src="data:image/svg xml,” width=”1085″>

Once this is done, clear the screen and type in the following commands to complete the process of Java home path configuration.

$ source /etc/environment

$ echo $JAVA_HOME

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/09/echo/13.jpg" data-lazy- height="174" src="data:image/svg xml,” width=”1008″>

Some Important Commands

Given below are certain commands you can use to check your version alongside other important things.

$ update-java-alternatives -1

(This command shows all the Java versions installed on your system.)

(Shows Java version you are using.)

(Shows version of Java you are currently using.)

(Shows the version of Java compiler.)

$ whichjava OR $ whereis java

(To find the location of Java.)

Remove Java Versions

To remove Java from your system, you can type in the following command:

$ sudo apt remove default-jdk default-jre

To remove the package:

$ dpkg –list | grep jdk


$ sudo apt remove jdk-16.0.2

Press “Y” followed by “ENTER” and the package will be uninstalled.

Should You Use JRE or JDK?

To run Java programs, you’ll need JRE (Java runtime environment). It is compatible with Windows, Linux, Mac, Solaris, and many more.

JDK (Java Development Kit) is used to develop Java applications. It is usually where most programmers start from. It depends on what you want to do.

When to Use JDK

  • You want to write Java programs. It comes with a compiler and Java application launcher.
  • Has access to the main Java libraries for coding via Java application launcher which opens JRE.

When to Use JRE

  • You have to use libraries and other files. It does not have compiler and error detection agents of its own.
  • When you have to use utility packages like math or data related sets and instructions.
  • To run applications running on Java.

Some Applications of Java

Java is mainly used in:

  • Building Android applications.
  • In developing web and cloud applications.
  • Software tools like Eclipse and Netbeans.
  • Chatbots.
  • Games.
  • Scientific and Enterprise applications

Conclusion

To stay up to date and get a hands-on experience of the latest packages and software, keeping our programs updated is a must. This check and balance can really help us a long way in keeping our system efficient, protected, and up to date.

About the author

<img data-del="avatar" data-lazy-src="https://kirelos.com/wp-content/uploads/2021/09/echo/myAvatar-150×150.png6133dc5e01f8b.jpg" height="112" src="data:image/svg xml,” width=”112″>

Zeeman Memon

Hi there! I’m a Software Engineer by degree, Blogger by skills who loves to write about tech, develop websites & do SEO. You can reach out to me on LinkedIn.