How to Install Java on Ubuntu 22.04

Install Java on Ubuntu 22.04

In this article, we will have explained the necessary steps to install Java on Ubuntu 22.04 LTS. Before continuing with this tutorial, make sure you are logged in as a user with sudo privileges. All the commands in this tutorial should be run as a non-root user.

Java is the most popular object-oriented, robust, platform-independent programming language. A large number of applications developed on Java required a system has Java installed.


  • Operating System with Ubuntu 22.04
  • Server IPv4 Address with Superuser Privileges (Root Access)
  • Gnome Terminal for Linux Desktop
  • PuTTy SSH client for Windows or macOS
  • Powershell for Windows 10/11
  • Familiar with APT Commands

Install Java on Ubuntu 22.04 LTS

Step 1. First, before you start installing any package on your Ubuntu server, we always recommend making sure that all system packages are updated.

sudo apt update
sudo apt upgrade

Step 2. Install Java on Ubuntu Linux.

Installing Java on your Ubuntu 22.04 Jammy Jellyfish is straightforward, Now we run the following command run the below-given command to install Java to your Linux system:

  • Install OpenJDK 11.
sudo apt install openjdk-11-jdk
  • Install OpenJDK 8.
sudo apt install openjdk-8-jdk
  • Install OpenJDK 17.
sudo apt install openjdk-17-jdk

Confirm the Java version:

java -version


Openjdk version "11.0.16" 2022-05-18
OpenJDK Runtime Environment (build 11.0.15+10-Ubuntu-0ubuntu0.22.04.1)
OpenJDK 64-Bit Server VM (build 11.0.15+10-Ubuntu-0ubuntu0.22.04.1, mixed mode, sharing)

Step 3. Set Default Java Version on Ubuntu 22.04.

Setting the default Java version applies in instances where you have multiple Java versions installed on your system. First, you need to list all the available versions:

sudo update-alternatives --config java


There are 3 choices for the alternative java (providing /usr/bin/java).

  Selection    Path                                         Priority   Status
* 0            /usr/lib/jvm/java-18-openjdk-amd64/bin/java   1811      auto mode
  1            /usr/lib/jvm/java-11-openjdk-amd64/bin/java   1111      manual mode
  2            /usr/lib/jvm/java-17-openjdk-amd64/bin/java   1711      manual mode
  3            /usr/lib/jvm/java-18-openjdk-amd64/bin/java   1811      manual mode

Press  to keep the current choice[*], or type selection number:

From the output, select the Java version you want to set as your default version by entering the number as shown above.

That’s all you need to do to install Java on Ubuntu 22.04 LTS Jammy Jellyfish. I hope you find this quick tip helpful. For further reading on the installed Java programming language, please refer to their official knowledge base. If you have questions or suggestions, feel free to leave a comment below.