DEV Community

Cover image for Configure JDK17 in Ubuntu 20.04
Kinjal
Kinjal

Posted on

Configure JDK17 in Ubuntu 20.04

Java 17 was released in September 2017. Java has multiple distributors as it is open source.
Download from jdk.java.net for openjdk. The commerical verion can be found from oracle.

In this setup openjdk x64 version is used.

Open JDK

Here are the steps to configure jdk17.

Create default jdk location if it is not there

$ mkdir /usr/lib/jvm/ cd $_ 
$ tar -xvzf ~/Downloads/openjdk-17.0.1_linux-x64_bin.tar.gz
Enter fullscreen mode Exit fullscreen mode

Inside /opt create a directory for jdk which will link to the actual jdk package.

$ cd /opt
$ mkdir jdk
$ ln -s /usr/lib/jvm/jdk-17.0.1 jdk17
Enter fullscreen mode Exit fullscreen mode

Once the following symlink is created, the next is to update ~/.bashrc file to update path for Java.

$ jdk17 -> /usr/lib/jvm/jdk-17.0.1
Enter fullscreen mode Exit fullscreen mode

Add the following lines to ~./bashrc

export JAVA_HOME=/opt/sun/jdk17/bin
export PATH=$PATH:$JAVA_HOME/bin 
Enter fullscreen mode Exit fullscreen mode

The setup is completed and now Ubuntu should be informed about the new package by using update-alternatives

$ sudo update-alternatives --install "/usr/bin/java" "java" "/usr/lib/jvm/jdk-17.0.1/bin/java" 0
$ sudo update-alternatives --install "/usr/bin/javac" "javac" "/usr/lib/jvm/jdk-17.0.1/bin/javac" 0
$ sudo update-alternatives --install "/usr/bin/javap" "javap" "/usr/lib/jvm/jdk-17.0.1/bin/javap" 0
$ sudo update-alternatives --set java /usr/lib/jvm/jdk-17.0.1/bin/java
$ sudo update-alternatives --set javac /usr/lib/jvm/jdk-17.0.1/bin/javac
$ sudo update-alternatives --set javap /usr/lib/jvm/jdk-17.0.1/bin/javap
Enter fullscreen mode Exit fullscreen mode

Now, verify the setup to know jdk location as it was provided

$ update-alternatives --list java 
$ update-alternatives --list javac
$ update-alternatives --list javap
Enter fullscreen mode Exit fullscreen mode

Finally, verify the java version

$ java -version
openjdk version "17.0.1" 2021-10-19
OpenJDK Runtime Environment (build 17.0.1+12-39) 
OpenJDK 64-Bit Server VM (build 17.0.1+12-39, mixed mode, sharing)
Enter fullscreen mode Exit fullscreen mode

Top comments (0)