How to Install Oracle Java (JDK 20 Updated) in Ubuntu 20.04 | Ubuntu 22.04

Last updated: March 22, 2023 — 7 Comments

This simple tutorial shows how to install the latest Oracle Java (JDK 20 so far) in Ubuntu Linux via the official binary package.

There used to be unofficial Ubuntu PPA to automate the process of installing Java JDK and setup the environment, however, discontinued. So, here’s the tutorial to manually install the Java package and set as default.

Install JDK 20 in Ubuntu:

Press Ctrl+Alt+T on keyboard to open a terminal window and follow the steps below one by one.

1. Download Java package

Firstly, go to oracle website and select download the .deb package:

It’s the 64-bit .deb package for modern PC and laptops, or tarball for ARM cpu architecture.

2. Install the .deb package

Once you downloaded the package, open terminal (Ctrl+Alt+T) and run the command below to install the deb package:

sudo apt install ~/Downloads/jdk-20_linux-x64_bin.deb

Here you may also double-click the .deb in file manager to install it via Ubuntu Software App.

For ARM device, run command to create ‘/usr/lib/jvm’ directory in case it does not exist:

sudo mkdir -p /usr/lib/jvm

Then, extract the tarball to that directory via:

sudo tar -zxf ~/Downloads/jdk-20_linux-aarch64_bin.tar.gz -C /usr/lib/jvm/

3. Set JDK 20 as default:

It installs the language files into ‘/usr/lib/jvm/jdk-20/‘ directory. To set it as default, do the following 2 steps one by one.

a.) Create symbolic links for the executable files:

sudo update-alternatives --install /usr/bin/java java /usr/lib/jvm/jdk-20/bin/java 1
sudo update-alternatives --install /usr/bin/javac javac /usr/lib/jvm/jdk-20/bin/javac 1
sudo update-alternatives --install /usr/bin/jar jar /usr/lib/jvm/jdk-20/bin/jar 1

Similarly, add links for other executable files (e.g., jarsigner, jlink, javadoc) as you need.

b.) Next, run the commands below one by one, and type number to select Java JDK 20 as default.

sudo update-alternatives --config java
sudo update-alternatives --config javac
sudo update-alternatives --config jar

When done, verify by running command in terminal:

java -version
javac -version


Option 1.) Set JAVA_HOME for current command console, that will work until you close it:

export JAVA_HOME=/usr/lib/jvm/jdk-20
setenv JAVA_HOME=/usr/lib/jvm/jdk-20

Option 2.) To make it permanent, create and edit config file via command:

sudo gedit /etc/profile.d/

then add following lines:

export J2SDKDIR=/usr/lib/jvm/jdk-20
export J2REDIR=/usr/lib/jvm/jdk-20
export PATH=$PATH:/usr/lib/jvm/jdk-20/bin:/usr/lib/jvm/jdk-20/db/bin
export JAVA_HOME=/usr/lib/jvm/jdk-20
export DERBY_HOME=/usr/lib/jvm/jdk-20/db

And create anther one for C shell:

sudo gedit /etc/profile.d/jdk.csh

add following lines and save it:

setenv J2SDKDIR /usr/lib/jvm/jdk-20
setenv J2REDIR /usr/lib/jvm/jdk-20
setenv PATH ${PATH}:/usr/lib/jvm/jdk-19/bin:/usr/lib/jvm/jdk-20/db/bin
setenv JAVA_HOME /usr/lib/jvm/jdk-20
setenv DERBY_HOME /usr/lib/jvm/jdk-20/db

Finally, change the permissions via command, and it should take place next time you log in.

sudo chmod +x /etc/profile.d/jdk.csh /etc/profile.d/


I'm a freelance blogger who started using Ubuntu in 2007 and wishes to share my experiences and some useful tips with Ubuntu beginners and lovers. Please comment to remind me outdated tutorial! And, notify me if you find any typo/grammar/language mistakes. English is not my native language. Contact me via [email protected] Buy me a coffee:

7 responses to How to Install Oracle Java (JDK 20 Updated) in Ubuntu 20.04 | Ubuntu 22.04

  1. Always good instructions for java installation.
    Thx Very much and CU next

  2. gracias!
    realmente util

  3. immeasurable thanks!!

  4. Thank you very much!!

  5. How to upgrade java 19.0.1 to 19.0.2?

Leave a Reply

Text formatting is available via select HTML.

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> 


This site uses Akismet to reduce spam. Learn how your comment data is processed.