Home  »  ArticlesGuidesHow ToLibrariesProgrammingSoftwareTechnologyTools   »   How to Install Java 22 (JDK 22) on Ubuntu 24.04 Noble Numbat

How to Install Java 22 (JDK 22) on Ubuntu 24.04 Noble Numbat

Java is a widely used programming language and computing platform. Java 22, the latest version, brings several new features and improvements that enhance performance, security, and developer productivity. If you’re looking to install Java 22 (JDK 22) on your Ubuntu 24.04 LTS Noble Numbat system, this guide will take you through the process step-by-step.

Why Java 22?

Java 22 introduces new language features, library enhancements, and performance improvements. Staying up-to-date with the latest Java version ensures you can take advantage of these enhancements and maintain compatibility with modern libraries and frameworks.


Before you start, make sure you have:

  1. An Ubuntu 24.04 LTS system.
  2. Sudo privileges to install software.

Step 1: Update Your System

First, update your package index to ensure you have the latest information on the available packages:

$ sudo apt update
$ sudo apt upgrade -y

Step 2: Install Java 22

Method 1: Using the Official Oracle JDK

  1. Download JDK 22:
    • Go to the official Oracle JDK download page: Oracle JDK Downloads.
    • Download the Linux x64 tar.gz file.
  2. Extract the JDK Archive:
$ sudo tar -xvzf jdk-22_linux-x64_bin.tar.gz -C /opt
  1. Set Up Environment Variables:
$ sudo nano /etc/profile.d/jdk22.sh

Add the following lines:

$ export JAVA_HOME=/opt/jdk-22
$ export PATH=$PATH:$JAVA_HOME/bin

Save and close the file, then make it executable:

$ sudo chmod +x /etc/profile.d/jdk22.sh
$ source /etc/profile.d/jdk22.sh
  1. Verify the Installation:
$ java -version

You should see output indicating that Java 22 is installed.

Method 2: Using OpenJDK (if available)

OpenJDK is an open-source implementation of the Java Platform, Standard Edition.

  1. Install OpenJDK:
$ sudo apt install -y openjdk-22-jdk
  1. Verify the Installation:
$ java -version

Step 3: Set Up JAVA_HOME

Setting the JAVA_HOME environment variable is important for some applications to find your Java installation.

  1. Open the environment file:
$ sudo nano /etc/environment
  1. Add the following line:
$ JAVA_HOME="/usr/lib/jvm/java-22-openjdk-amd64"

Adjust the path if you installed the Oracle JDK:

$ JAVA_HOME="/opt/jdk-22"
  1. Load the new environment variable:
$ source /etc/environment

Step 4: Verify the JAVA_HOME Variable

To ensure that the JAVA_HOME variable is set correctly:

$ echo $JAVA_HOME

You should see the path to your Java 22 installation.

Step 5: Set Java 22 as the Default Java Version

If you have multiple Java versions installed, you can set Java 22 as the default:

$ sudo update-alternatives --install /usr/bin/java java /opt/jdk-22/bin/java 1
$ sudo update-alternatives --config java

Follow the on-screen instructions to select Java 22.


Congratulations! You have successfully installed Java 22 (JDK 22) on your Ubuntu 24.04 LTS Noble Numbat system. You are now ready to develop and run Java applications using the latest features and improvements offered by Java 22. For more information and resources, check out the official Java documentation.

Found this article interesting? Follow Brightwhiz on Facebook, Twitter, and YouTube to read and watch more content we post.