Share your love
Install OpenJDK 17 on Ubuntu 22.04
This tutorial intends to show you to Install OpenJDK 17 (Java 17) on Ubuntu 22.04.
OpenJDK is a free, open-source version of the Java Development Kit for the Java Platform, Standard Edition (Java SE). OpenJDK, which stands for Open Java Development Kit, originated from an effort initiated by Sun Microsystems in 2006 and is now sponsored and led by Oracle. The project is licensed under the GNU General Public License (GNU GPL) version 2 with a linking exception. Without the linking exception, components that linked to the Java class library would be subject to the terms of the GPL license.
Steps To Install OpenJDK 17 on Ubuntu 22.04
To complete this guide, you must log in to your server as a non-root user with sudo privileges. To do this, you can follow our guide on Initial Server Setup with Ubuntu 22.04.
Install Java Development Kit 17 on Ubuntu 22.04
First, you need to update your local package index with the command below:
sudo apt update
Download OpenJDK 17
At this point, you need to visit the JDK Downloads page to download the latest archive by using the wget command:
sudo wget https://download.java.net/java/GA/jdk17.0.2/dfd4a8d0985749f896bed50d7138ee7f/8/GPL/openjdk-17.0.2_linux-x64_bin.tar.gz
Then, extract your downloaded file with the command below:
sudo tar xvf openjdk-17.0.2_linux-x64_bin.tar.gz
Next, move your extracted file to the /opt directory:
sudo mv jdk-17.0.2 /opt/
Configure Java Environment Path on Ubuntu 22.04
At this point, you need to configure the Java home path by using the following command:
sudo tee /etc/profile.d/jdk17.sh <<EOF
export JAVA_HOME=/opt/jdk-17.0.2
export PATH=\$PATH:\$JAVA_HOME/bin
EOF
Source your profile file with the following command:
source /etc/profile.d/jdk17.sh
Verify your Java Home path:
echo $JAVA_HOME
Output
/opt/jdk-17.0.2
Also, you can verify your Java installation by checking its version:
java -version
Output
openjdk version "17.0.2" 2022-01-18
OpenJDK Runtime Environment (build 17.0.2+8-86)
OpenJDK 64-Bit Server VM (build 17.0.2+8-86, mixed mode, sharing)
Install Java 17 From Apt Repository
Another way that you can use to install Java 17, is to use the Apt repository on Ubuntu 22.04.
First, you need to update your local package index with the command below:
sudo apt update
Then, use the command below to install Java 17:
sudo apt install openjdk-17-jre-headless -y
Verify your Java installation by checking its version:
java -version
Output
openjdk version "17.0.2" 2022-01-18
OpenJDK Runtime Environment (build 17.0.2+8-86)
OpenJDK 64-Bit Server VM (build 17.0.2+8-86, mixed mode, sharing)
Test Java 17 Installation on Ubuntu 22.04
At this point, we will show you to create a sample project to see that your Java is working correctly on Ubuntu 22.04.
Create and open the hello world file with your favorite text editor, here we use the vi editor:
vi HelloWorld.java
Add the following content to the file:
public class HelloWorld {
public static void main(String[] args) {
// Prints "Hello, World" to the terminal window.
System.out.println("Hello, World");
}
}
When you are done, save and close the file.
Then, compile and run your Java code:
java HelloWorld.java
Output
Hello, World
That’s it, you are done.
Conclusion
At this point, you have learned to Install OpenJDK 17 or Java 17 on Ubuntu 22.04.
Hope you enjoy it. You may be interested in these articles on the Orcacore website:
How To Install OTRS on Ubuntu 22.04