Install/Upgrade Oracle JDK 17 (Java 17 LTS) on Linux Mint 20

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 Oracle Java 17 (JDK 17) on Linux Mint 20.

For users wishing to install the OpenJDK 17 version, please see the tutorial How to Install OpenJDK 17 on Linux Mint 20.

Update Linux Mint System

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

sudo apt update && sudo apt upgrade -y

Install Oracle 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, but it is well known and respected and as safe as any other third-party repository.

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 JDK 17 (Java 17 LTS) on Linux Mint 20

Type Y, then press the ENTER KEY to proceed.

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

Example Message:

How to Install Oracle JDK 17 (Java 17 LTS) on Linux Mint 20

Select <Yes> to proceed and complete the installation. If you choose <No>, the installation will stop.

Example:

How to Install Oracle JDK 17 (Java 17 LTS) on Linux Mint 20

Verify the installation was successful using the –version command:

java --version

Example output:

How to Install Oracle JDK 17 (Java 17 LTS) on Linux Mint 20

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

Install Oracle 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.

Example:

wget https://download.oracle.com/java/17/latest/jdk-17_linux-x64_bin.deb

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 JDK 17 (Java 17 LTS) on Linux Mint 20

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 JDK 17 (Java 17 LTS) on Linux Mint 20

Install Oracle 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 https://download.oracle.com/java/17/latest/jdk-17_linux-x64_bin.tar.gz

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.0.1 /opt/jdk-17

Now you need to set the environment variables as below:

export JAVA_HOME=/opt/jdk-17
export PATH=$PATH:$JAVA_HOME/bin

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

java --version
echo $JAVA_HOME

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)
/opt/jdk17

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 the famous Hello World.

First, create the Java program file as follows

sudo nano hello.java

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:

javac hello.java

Finally, run the Java code with the following command:

java hello

Example output:

How to Install Oracle JDK 17 (Java 17 LTS) on Linux Mint 20

Congratulations, everything is working correctly.

Comments and Conclusion

In the tutorial, you have learned how to download and install the latest version of Oracle JDK 17 LTS on your Linux Mint 20 system.

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.



Follow LinuxCapable.com!

Like to get automatic updates? Follow us on one of our social media accounts!