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: