Install Oracle Java 17 LTS (JDK 17) on Ubuntu 20.04

Java is a general-purpose, class-based, object-oriented multipurpose programming language that is popular due to the design of having lesser implementation dependencies, meaning that the compiled Java code can be run on all platforms that support Java without the need for recompilation. Java is also fast, secure, and reliable, therefore. It is widely used for developing Java applications in laptops, data centers, game consoles, scientific supercomputers, cell phones, etc.

JDK 17 (JDK 17) has brought forward new language enhancements, updates to the libraries, support for new Apple computers, removals and deprecations of legacy features, and work to ensure Java code written today will continue working without change in future JDK versions.

In the following tutorial, you will learn how to install the latest Java 17 (JDK 17) on Ubuntu 20.04 LTS Focal Fossa.

For users wishing to install the OpenJDK 17 version, please see the tutorial How to Install OpenJDK 17 on Ubuntu 20.04.

Update Ubuntu System

Update your Ubuntu operating system to make sure all existing packages are up to date:


sudo apt update && sudo apt upgrade -y

Install Java JDK 17 – APT PPA Method

The first option will be to install Java 17 JDK from the ppa:linuxuprisingrepository. Currently, Java 17 is featured in this PPA. This is a non-official repository, as always with any PPA use with caution and at your own risk.

First, import the PPA using the following command in your terminal:

sudo add-apt-repository ppa:linuxuprising/java -y

Next, update your APT repository.

sudo apt update

To install using the APT package manager, execute the following command:

sudo apt-get install oracle-java17-installer oracle-java17-set-default

Example output:

How to Install Oracle Java 17 LTS (JDK 17) on Ubuntu 20.04

Note that you will need to accept Oracle’s terms during the installation.


Verify the installation was successful using the –version command:

java 17 2021-09-14 LTS
Java(TM) SE Runtime Environment (build 17+35-LTS-2724)
Java HotSpot(TM) 64-Bit Server VM (build 17+35-LTS-2724, mixed mode, sharing)

To remove Java 17 JDK using the apt package manager method, run the following command:

sudo apt autoremove oracle-java17-installer oracle-java17-set-default --purge

Example output:

How to Install Oracle Java 17 LTS (JDK 17) on Ubuntu 20.04

Type Y, then press ENTER KEY to proceed with the uninstall.

See also  How to Install VeraCrypt on Debian 11 Bullseye

Install Java JDK 17 – DPKG Method

Install Dependency Packages

To successfully install JDK 17, you need to install the following packages.

sudo apt install libc6-i386 libc6-x32 curl -y

Install Java 17 DPKG Method

The easier option but the most restrictive is to install Java JDK 17 using the dpkg command, which is a tool to install, build, remove and manage .deb packages.


First, download the .deb package from Java’s download page, or copy and paste the link into a wget command in your terminal.



Note this link should work if it doesn’t go to the website to get a new one.

Once you have downloaded the .deb package, run the following command in your terminal to install Java:

sudo dpkg -i jdk-17_linux-x64_bin.deb

Example output:

How to Install Oracle Java 17 LTS (JDK 17) on Ubuntu 20.04

Remove Java 17 DPKG Method

If you no longer require Java JDK 17 and have installed the software using the .deb JDK package, you can use the following dpkg command with the -r flag option that will remove the package as the example below:


sudo dpkg -r jdk-17

Example output:

How to Install Oracle Java 17 LTS (JDK 17) on Ubuntu 20.04

Install Java JDK 17 – Manual Method

The second and most recommended option is to install Java JDK 17, the manual way that benefits users more freedom and power on what they want and where installed on their system.

Install Dependency Packages

To successfully install Java JDK 17, you need to install the following packages.

sudo apt install libc6-i386 libc6-x32 curl -y

Download Latest Java 17 Build

Visit the downloads page to get the latest build version link, then use the following curl command:

curl  -O

Install the CURL package if you find that the above command returns an error.

sudo apt install curl -y

Once the download is complete, you need to extract the archive as follows:


tar -xvf jdk-17_linux-x64_bin.tar.gz

Configure and Install Java 17

Next, move the extracted archive directory into the /opt/ location:

sudo mv jdk-17.{version} /opt/jdk17

Note, you need to add the version number, such as jdk-17.02 in {version} with the above command.

See also  How to Install AnyDesk on Ubuntu 22.10/22.04/20.04

Now you need to set the environment variables as below:

export JAVA_HOME=/opt/jdk17
export PATH=$PATH:$JAVA_HOME/bin

Java 17 is now installed. To confirm, use the following commands:

java --version

If installed correctly, you should see the following output:

java 17 2021-09-14 LTS
Java(TM) SE Runtime Environment (build 17+35-LTS-2724)
Java HotSpot(TM) 64-Bit Server VM (build 17+35-LTS-2724, mixed mode, sharing)

As you can see, you can see the version is the latest Java 17 JDK build.


Test Java – Create Hello World Application

To finish off, it is always handy to test installations of these kinds to confirm everything is working correctly after being installed. The easy way is to create a small program script to test using the famous Hello World.

First, create the Java program file as follows

sudo nano

Next, add the following Java code into the file:

public class hello {
  public static void main(String[] args) {
    System.out.println("G'day from LinuxCapable!");

Save the file (CTRL+O), then exit (CTRL+X).

Next, compile the code:


Finally, run the Java code with the following command:


java hello

Example output:

How to Install Oracle Java 17 LTS (JDK 17) on Ubuntu 20.04

Congratulations, everything is working correctly.

Comments and Conclusion

In the tutorial, you have learned how to download and install the latest version of Java 17 (JDK 17) on Ubuntu 20.04 LTS Focal Fossa Desktop or Server.

Overall, for developers to upgrade Java can be a painstaking task, but in the long term, upgrading to Java 17 will be worth the goal of being an LTS version support will be around along with improvements for quite some time.

Not what you were looking for? Try searching for additional tutorials.

10 thoughts on “Install Oracle Java 17 LTS (JDK 17) on Ubuntu 20.04”

  1. I followed the instructions do install with a .deb package, but it says I have open JDK version 11. I removed it with the above command and it was removed.

    Yet, when I entered java -version it said I have version 11, but when I tried to uninstall it it says that it isn’t installed. Can someone help me here? I’m confused. As well, what about the page on the oracle website that talks about the jdk installer? Does that matter at all? I’m confused here, unless I’m missing something.

    • Hi Chris,

      What version are you trying to install?

      You can install Open-JDK 17 now with.

      sudo apt install openjdk-17-jre-headless

      remove OpenJDK 11 with

      sudo apt remove openjdk-11-jre-headless

      You can keep both if you wanted.

      Depends if you want Open or the Oracle.

      For Oracle, need to compile, .deb, or PPA. I just tested the .deb, works fine.


      sudo update-alternatives –config java

      Example output on my test machine

      joshua@main-pc:~$ sudo update-alternatives –config java
      There are 2 choices for the alternative java (providing /usr/bin/java).

      Selection Path Priority Status
      * 0 /usr/lib/jvm/java-17-openjdk-amd64/bin/java 1711 auto mode
      1 /usr/lib/jvm/java-11-openjdk-amd64/bin/java 1111 manual mode
      2 /usr/lib/jvm/java-17-openjdk-amd64/bin/java 1711 manual mode

      That command will let you pick a default too, or remove what you don’t need


      • Thanks — got it. I came across another page this morning about installing java with the command you gave me. But I’m having trouble installing open office. By the way, I need some more help if you can swing it. I want to installs open office, but am having trouble. I have a .tar.gz package in my downloads directory. Can I just trash that? i want to start over with this.

        Second, i have an en-US folder from a previous download, but I can’t send that to the trash/delete it. It says I don’t have write privileges. Not sure what to do about this. How do I get rid of this? Iike I said I want to start over.

        I think i came across a page on how to install OpenOffice, but I can’t find it now. Can you help me out with the above, and with how to install this? The instructions on the open office site are kind of unclear, or I don’t know enough yet to properly do it.

        By the way, I accidentally downloaded the .rpm file the first time, not the .deb file/package. Would that have something to do with it? When I try to remove it I noticed that the extensions for the packages have .rpm

        • Sorry, Chris for the late reply, been busy irl.

          Think some googling about .deb packages, .rpm packages and may come in handy so much to learn since you are getting into Linux then I can put into comments but overall The .deb files are meant for distributions of Linux that derive from Debian (Ubuntu, Linux Mint, etc.). The .rpm files are used primarily by distributions that derive from Redhat-based distros (Fedora, CentOS, RHEL) as well as by the openSuSE distro.

          I have been meaning to create tutorials on Open Office, I will get something together soon for everyone.

  2. Another thing– will this even work on elementary OS? I thought it might since it’s based on Debian/Ubuntu. Just starting to learn about Linux; going to switch over from Mac OS eventually, or use them both.

  3. Dzięki za artykuł. Jest bardzo pomocny 🙂
    Mała uwaga przy konfiguracji ręcznej podałeś komendę:

    sudo mv jdk-17 /opt/jdk17

    Powinno być:

    sudo mv jdk-17.0.2 /opt/jdk17

    Dziękuję i Pozdrawiam 🙂


Leave a Comment