Install Adoptium Temurin OpenJDK 21 LTS on Ubuntu 24.04

Eclipse Adoptium’s main objective is to produce high-quality runtimes and the associated technology to be used within the Java Ecosystem. This has been achieved through close partnerships with external projects such as OpenJDK for providing the Java SE runtime implementation.

The AdoptOpenJDK project was instituted in 2017 following a lengthy discussion about the lack of an open-source and reproducible build and test system for OpenJDK across multiple platforms. From that moment onwards, the growth of Adoptium Temurin OpenJDK has been tremendous until becoming the leading provider of high-quality OpenJDK for use in enterprise systems, traditional servers, desktops, and even large mainframes.

AdoptJDK offers binary files for installation on various devices such as Windows, Linux, macOS e.t.c

In this guide, we will take a systematic walk through the installation of the amazing Adoptium Temurin OpenJDK 21 on Ubuntu 24.04.

Step 1. Update your system

Ensure that your system and all the available packages are updated to their latest stable versions as below.

sudo apt update && sudo apt upgrade
sudo apt install wget

Step 2. Download Adoptium Temurin OpenJDK 21

Now proceed and download AdoptOpenJDK 21 binary file from the official Adoptium Downloads page.

Alternatively, you can download the archive from your Ubuntu 24.04 terminal using the command:

wget https://github.com/adoptium/temurin21-binaries/releases/download/jdk-21.0.7%2B6/OpenJDK21U-jdk_x64_linux_hotspot_21.0.7_6.tar.gz

Extract the archive.

tar -xvf OpenJDK21U-jdk_x64_linux_hotspot_21.*.tar.gz

Step 3. Install Adoptium Temurin OpenJDK 21 on Ubuntu

Move the extracted folder to the /opt/ directory.

sudo mv jdk-21.0.7+6 /opt/

Export the environment variables.

$ vim ~/.bashrc
export JAVA_HOME=/opt/jdk-21.0.7+6
export PATH=$PATH:$JAVA_HOME/bin 

$ source ~/.bashrc

Verify your AdoptOpenJDK 21 installation as below.

$ echo $JAVA_HOME
/opt/jdk-21.0.7+6

Check the installed Java version on Ubuntu 20.04|18.04.

$ java --version
openjdk 21.0.7 2025-04-15 LTS
OpenJDK Runtime Environment Temurin-21.0.7+6 (build 21.0.7+6-LTS)
OpenJDK 64-Bit Server VM Temurin-21.0.7+6 (build 21.0.7+6-LTS, mixed mode, sharing)

Step 4. Set Default Java Version on Ubuntu 24.04/22.04.

In cases where you have multiple Java instances on your Ubuntu 24.04/22.04, you are required to set the default version of Java to be used.

Since AdoptJDK 21 has not been added to the /usr/bin/java path we will add it as below, otherwise, you won’t see it in the java alternatives.

sudo update-alternatives --install /usr/bin/java java /opt/jdk-21.0.7+6/bin/java 1

List all the Java versions installed on Ubuntu 24.04/22.04.

sudo update-alternatives --config java

Sample Output:

$ sudo update-alternatives --config java
There is 1 choice for the alternative java (providing /usr/bin/java).

  Selection    Path                        Priority   Status
------------------------------------------------------------
* 0            /opt/jdk-21.0.7+6/bin/java   1         auto mode
  1            /opt/jdk-21.0.7+6/bin/java   1         manual mode

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

From the above output, select the version to set as the default version by entering the choice number as above.

Verify the set Java version.

$ java -version
openjdk 21.0.7 2025-04-15 LTS
OpenJDK Runtime Environment Temurin-21.0.7+6 (build 21.0.7+6-LTS)
OpenJDK 64-Bit Server VM Temurin-21.0.7+6 (build 21.0.7+6-LTS, mixed mode, sharing)

Step 5. Set global JAVA_HOME Environment Variable.

This path is used by Java applications to determine the exact path where Java has been installed on your Ubuntu system and the version to use when running Java applications.

Identify the Java Path.

$ whereis java
java: /usr/bin/java /usr/share/java /opt/jdk-21.0.7+6/bin/java

We will set a persistent path by editing the below file.

sudo vi /etc/profile

In the file, add the below line specifying the exact path where your Java has been installed.

JAVA_HOME="/path/to/java/install"

In my case, the line will be as below.

export JAVA_HOME=/opt/jdk-21.0.7+6
export PATH=$PATH:$JAVA_HOME/bin 

Now, reload your shell:

source /etc/profile

Verify the set PATH variable.

$ echo $JAVA_HOME
/opt/jdk-21.0.7+6/bin

Step 6. Test the Java Installation.

Having successfully installed Adoptium Temurin OpenJDK 21 on Ubuntu 24.04|22.04 we need to test it and see if it works perfectly.

Create a sample file say, HelloWord.java. This HTML file is a simple Java application to print a Hello World message.

cat > HelloWorld.java <<EOF
public class helloworld {
  public static void main(String[] args) {
    System.out.println("Hello Java World from Kenya! AdoptJDK is amazing!");
  }
}
EOF

Compile the Java code as below:

java HelloWorld.java

Sample Output:

$ java HelloWorld.java
Hello Java World from Kenya! AdoptJDK is amazing!

Conclusion.

From the above output, it is safe to assume that our Adoptium Temurin OpenJDK 21 on Ubuntu 24.04|22.04 installation is working fine. I hope this guide was of importance to you.

See more guides on this page:

Join our Linux and open source community. Subscribe to our newsletter for tips, tricks, and collaboration opportunities!

Recent Post

Unlock the Right Solutions with Confidence

At CloudSpinx, we don’t just offer services - we deliver clarity, direction, and results. Whether you're navigating cloud adoption, scaling infrastructure, or solving DevOps challenges, our seasoned experts help you make smart, strategic decisions with total confidence. Let us turn complexity into opportunity and bring your vision to life.

Leave a Comment

Your email address will not be published. Required fields are marked *

Related Post

WireGuard is a modern VPN that uses peer-to-peer kind of connectivity to establish the connection. It is a simple and […]

On latest releases of Rocky, AlmaLinux, CentOS operating systems, the old ifup and ifdown commands are not installed by default. […]

In this guide, we are going to look at how to install Wiki.js on a Debian 12/11 Linux system. Wiki.js […]

Let's Connect

Unleash the full potential of your business with CloudSpinx. Our expert solutions specialists are standing by to answer your questions and tailor a plan that perfectly aligns with your unique needs.
You will get a response from our solutions specialist within 12 hours
We understand emergencies can be stressful. For immediate assistance, chat with us now

Contact CloudSpinx today!

Download CloudSpinx Profile

Discover the full spectrum of our expertise and services by downloading our detailed Company Profile. Simply enter your first name, last name, and email address.