How to install Adoptium Temurin OpenJDK 17 on Ubuntu 22.04
Eclipse Temurin is the open-source Java SE build based upon OpenJDK.
This guide will show how to install the Adoptium Temurin OpenJDK 17 on Ubuntu 22.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
Step 2. Download Adoptium Temurin OpenJDK 17
Now, download AdoptOpenJDK 17 binary file from the official Adoptium Downloads page.
Alternatively, you can download the archive from your Ubuntu 22.04 terminal using the command:
Extract the archive file by using the command:
tar xzfv OpenJDK17U-jdk_x64_linux_hotspot_17.0.7_7.tar.gz
Step 3. Install Adoptium Temurin OpenJDK 17 on Ubuntu 22.04.
Move the extracted folder to the /opt/ directory.
sudo mv jdk-17.0.7+7 /opt/
Export the environment variables.
vim ~/.bashrc export JAVA_HOME=/opt/jdk-17.0.7+7 export PATH=$PATH:$JAVA_HOME/bin source ~/.bashrc
Verify your AdoptOpenJDK 17 installation as below.
echo $JAVA_HOME /opt/jdk-17.0.7+7
Check the installed Java version on Ubuntu 22.04.
java --version openjdk 17.0.7 2023-04-18 OpenJDK Runtime Environment Temurin-17.0.7+7 (build 17.0.7+7) OpenJDK 64-Bit Server VM Temurin-17.0.7+7 (build 17.0.7+7, mixed mode, sharing)
Step 4. Set Default Java Version on Ubuntu 22.04.
In cases where you have multiple Java instances on your Ubuntu 22.04, you are required to set the default version of Java to be used.
Since AdoptJDK 17 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-17.0.7+7/bin/java 1
List all the Java versions installed on Ubuntu 22.04.
sudo update-alternatives --config java
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-17.0.7+7/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.
In my case, the line will be as below.
export JAVA_HOME=/opt/jdk-17.0.7+7/bin/java export PATH=$PATH:$JAVA_HOME/bin
Now apply the changes made by logging out and logging in again to your system or issue the source command as below.
Verify the set PATH variable.
echo $JAVA_HOME /opt/jdk-17.0.7+7/bin
From the above output, it is safe to assume that our Adoptium Temurin OpenJDK 17 on Ubuntu 22.04 installation works fine. I hope this guide was of importance to you.