Adam. R

How to install JDK 17 on Ubuntu!

Created March 13, 2022

Introduction

JDK 17 has been released recently, so I decided to tell you how to install it on Ubuntu. Fun fact, my first ever post was "How to install JDK 16 on Ubuntu!" Let's get started.


Installation

Option 1

There are 2 ways you can install JDK 17, let's do the first option. Since Java OpenJDK 17 is an open-source implementation of the Java SE platform. Since the OpenJDK versions available in the default repositories are not up to date, we will have to download the Open-source JDK 17 using the wget command.

wget https://download.java.net/java/GA/jdk17.0.2/dfd4a8d0985749f896bed50d7138ee7f/8/GPL/openjdk-17.0.2_linux-x64_bin.tar.gz

Extract the downloaded tarball.

tar xvf openjdk-17.0.2_linux-x64_bin.tar.gz

Then move the extracted file to the /opt/ directory as shown.

sudo mv jdk-17.0.2/ /opt/jdk-17/

Then we need to set the environment variables.

echo 'export JAVA_HOME=/opt/jdk-17' | tee -a ~/.bashrc
echo 'export PATH=$PATH:$JAVA_HOME/bin '|tee -a ~/.bashrc
source ~/.bashrc

Verify the Java installation as below.

echo $JAVA_HOME
/opt/jdk-17

Check the installed version of Java.

java --version
openjdk 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)

Option 2

For this option, we download the production-ready Java from the Java SE Downloads page. Alternatively, one can install Oracle JDK 17 on Ubuntu 20.04/18.04 using the “Linux Uprising” team PPA installer script which automatically downloads and sets the default Java version on Ubuntu 64-bit based systems. First, we need to add the PPA as below.

sudo add-apt-repository ppa:linuxuprising/java

Then install Oracle JDK 17 as shown.

sudo apt update
sudo apt install oracle-java17-installer

You will see this installer window where you are supposed to agree to the License Terms. Verify the installed version of Java by checking the version.

java -version
java version "17.0.1" 2021-10-19 LTS
Java(TM) SE Runtime Environment (build 17.0.1+12-LTS-39)
Java HotSpot(TM) 64-Bit Server VM (build 17.0.1+12-LTS-39, mixed mode, sharing)

$ javac -version
javac 17

Conclusion

There you go! You have just installed JDK (Java Development Kit) 17 on Ubuntu! If you found this usful then please share this and follow me! Also check out my Buy Me A Coffee!

Buy Me A Coffee how2ubuntu