Categories: TutorialsUbuntu

​​How To Install Java with Apt on Ubuntu 22.04?

Java is a free-to-use object-oriented programming language. Java supports multithreading environments and incorporates complex technologies like machine learning and virtual reality. It is frequently used to develop web, desktop, android applications, games, etc. This article will demonstrate the installation of Java on Linux/Ubuntu 22.04 LTS.

How to Install Java With Advanced Package Tool (Apt) on Linux/Ubuntu?

Java is based on the following components:

  • JDK (Java Development Kit) provides a software development environment for building applications.
  • JRE (Java Runtime Environment) is an essential software component to run Java programs.
  • JVM (Java Virtual Machine) is a Java compiler, i.e., JVM converts Java source code into machine language.
Sponsored

The following steps will discuss the installation of the latest version of Java on Ubuntu 22.04 systems:

Step 1: Update System Repositories

The first step to install Java is to update the system package:

$ sudo apt update

Step 2: Install Dependencies

The packages of dependencies are installed before installing JDK. By executing the following command, the math standard library will be installed:

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

It will take a few seconds for the installation process to complete.

Step 3: Download the Deb file of JDK 20

The wget command line utility is used to download the JDK 20 “.deb” package from the official page by executing the following command:

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

It can be seen from the above image that the .deb package of JDK 20 is successfully installed.

Step 4: Install Java

“apt” (Advanced Packaging Tool) is a high-level package management system, i.e., it automatically checks and downloads all dependencies related to the package. It is the default package management tool in Debian. Java can be installed by using apt as follows:

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

From the above image, it can be seen that Java is installed successfully.

Sponsored

Step 5: Configuration of Java Environment

After successful installation, the Java environment is configured by executing the following commands in Terminal one by one:

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

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

> export PATH=$PATH:$JAVA_HOME/bin

> EOF

From the below image, it can be seen that the Java environment is configured and exported.

Step 6: JDK Profile Execution

Finally, the “Jdk20.sh” profile file is executed by using the below-given command:

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

Step 7: Verify Java Installation

Java installation can be verified by checking the version of Java:

$ java -version

From the below image, it can be verified that the latest version of Java is successfully installed.

How to Uninstall Java From Ubuntu 22.04?

Java and its related directories can be removed by executing the following command:

$ sudo rm -rf /usr/lib/jvm/*

From the output image, it can be verified that Java is successfully uninstalled.

Conclusion

Java is installed by first updating the system repositories, and then installing dependencies. After that, download the latest version of JDK, i.e., JDK 20, and then install it by executing the “sudo apt install ./jdk-20_linux-x64_bin.deb” command. This article has demonstrated the installation of Java on Linux/Ubuntu 22.04 LTS.

Ubuntu Server Admin

Recent Posts

From sales development to renewals: Mariam Tawakol’s career progression at Canonical

Career progression doesn’t follow a single path – and at Canonical, we embrace that. Our…

9 hours ago

In pursuit of quality: UX for documentation authors

Canonical’s Platform Engineering team has been hard at work crafting documentation in Rockcraft and Charmcraft…

9 hours ago

Ubuntu 24.10 (Oracular Oriole) reached End of Life on 10th July 2025

This is a follow-up to the End of Life warning sent earlier to confirm that…

1 day ago

Canonical announces Charmed Feast: A production-grade feature store for your open source MLOps stack

July 10, 2025: Today, Canonical announced the release of Charmed Feast, an enterprise solution for…

1 day ago

Ubuntu Adding NVIDIA 575 Driver Support for 24.04 & 22.04 LTS

For NVIDIA users, the latest 575 series driver will be available soon in Ubuntu repository.…

2 days ago

Amarok Released 3.3 with Qt6/KF6 Port & GStreamer Backend

Amarok, the free open-source KDE music player, released new 3.3 version on Tuesday, named “Far…

2 days ago