Ubuntu

How to Install Java on Ubuntu 22.04

Java is a general-purpose and free-to-use programming language utilized for creating distributed and localized applications. This programming language is also used to develop computer, video, and mobile games. It assists in creating modern games that incorporate complex technology such as virtual reality and machine learning.

Components of Java

The Java programming language is based on these three primary components:

JVM: JVM or “Java Virtual Machine” is an engine that converts the Java byte code into machine language.

JRE: JRE or “Java Runtime Environment” creates an environment where Java-related files are executed. It is a software bundle that comprises JVM, Java Classloader, and libraries.

JDK: JDK is an acronym for “Java Development Kit“, and it offers a software development environment for building Java applications.

This write-up will discuss the procedure to install the latest Java version on Ubuntu 22.04 using two different methods. So, let’s start!

How to install OpenJDK 18 on Ubuntu 22.04

OpenJDK comprises separate packages for JDK and JRE for developing and running Java-based applications.

Want to install OpenJDK on Ubuntu 22.04? If yes, then follow the below-given procedure.

Step 1: Update system repositories

Press “CTRL+ALT+T” to open the terminal of Ubuntu 22.04 and run the below-given commands to update system repositories:

$ sudo apt update

Step 2: Install OpenJDK 18 on Ubuntu 22.04

Based on your preferences, install OpenJDK or JRE on your system. Here is the command that assists in installing OpenJDK18 on Ubuntu 22.04:

$ sudo apt install -y openjdk-18-jdk

Step 3: Install OpenJDK18 JRE on Ubuntu 22.04

In the other case, install OpenJDK 18 JRE by utilizing the following command:

$ sudo apt install -y openjdk-18-jre

That’s it! OpenJDK 18 JRE on your Ubuntu 22.04 system.

How to install Java SE Development Kit 18 on Ubuntu 22.04

You can also utilize the Java SE Development Kit for the development as it offers several tools for writing, compiling, debugging, and executing Java applications.

For the installation of Java SE Development Kit 18 on your Ubuntu 22.04 system, check out the below-given procedure.

Step 1: Update system repositories

Press “CTRL+ALT+T” to open the terminal of Ubuntu 22.04 and run the below-given commands to update system repositories:

$ sudo apt update

Step 2: Install required dependencies

In the next step, we will install the required dependencies for the Java SE Development Kit 18:

$ sudo apt install -y libc6-x32 libc6-i386

Step 3: Download Java SE Development Kit 18

Then, download the Java SE Development Kit 18 package from the official page with the help of the following “wget” command:

$ wget https://download.oracle.com/java/18/latest/jdk-18_linux-x64_bin.deb

Step 4: Install Java SE Development Kit 18 on Ubuntu

Next, utilize the below-given command for the installation of Java SE Development Kit 18 on Ubuntu 22.04:

$ sudo apt install ./jdk-18_linux-x64_bin.deb

Step 5: Configure Java Environment

After installing the mentioned Java Kit package, you have to configure the Java environment. To do so, one by one execute the given command in Ubuntu 22.04 terminal:

$ cat <<EOF | sudo tee /etc/profile.d/jdk18.sh

> export JAVA_HOME=/usr/lib/jvm/jdk-18

> export PATH=\$PATH:\$JAVA_HOME/bin

> EOF

Now, write out the “source” command to execute the profile file “jdk18.sh”:

$ source /etc/profile.d/jdk18.sh

Step 6: Verify Java version

Lastly, validate the version of the installed Java on Ubuntu 22.04:

$ java -version

We have compiled two different methods for the installation of Java on Ubuntu 22.04. Select any of them according to your requirements.

Conclusion

To install the latest Java version on Ubuntu 22.04, either execute “$ sudo apt install -y openjdk-18-jdk” or the “$ sudo apt install -y openjdk-18-jre” command. You can also download the Java SE Development Kit from the official page and install it with the help of the “$ sudo apt install ./jdk-18_linux-x64_bin.deb” command. This write-up discussed two different methods to install Java on Ubuntu 22.04.

About the author

Sharqa Hameed

I am a Linux enthusiast, I love to read Every Linux blog on the internet. I hold masters degree in computer science and am passionate about learning and teaching.