2 ways to install Oracle Java 17 on Ubuntu 20.04 | 22.04 LTS

Oracle Java 17 is not available to install on Ubuntu 20.04 or 22.04 LTS using the default main repository of these Linux. Hence, here we will know the steps to set up the same using the command terminal.

What is the key difference between Oracle Jave and OpenJDK?

Well, if you don’t want particularly the Java from Oracle then the OpenJDK is always available with the latest and old versions to install on Ubuntu (via main repo). But for those who don’t know exactly the difference between Oracle Java and OpenJDK, let’s talk a little bit about that.

Oracle JDK 11, Oracle JDK Java 8, and Oracle JRE with Java Web Start in Java 8 have been licensed under the OTN License Agreement for Java SE. Hence, it is free for personal and development purposes but there are some restrictions for business and commercial or production usage, which means if someone wants to use any of them for business purposes they need to obtain a commercial license. However, since Java 17, Oracle has made it free to use for all users. Whereas OpenJDK has the GNU General Public License (GNU GPL), it is an open-source version of Oracle Java with the same capabilities but free for all without any restriction. That’s is the reason why most of the Linux distributions provide OpenJDK through its default main repository.

What is the Java programming language?

Java is primarily a programming language that pupils and students often get to know in computer science classes. Initially, the JAVA belongs to the company “Sun Microsystems”, however later it was acquired by Oracle in 2010.
It has been used widely by developers or programmers to quickly create applications or scripts.  Well, Java is one of the object-oriented programming languages. This means that the associated program code is structured in classes and objects. For example, an object of the class “pen” can be created. The class defines which properties “pen” has: color, length, shape.  A concrete object is a realization of the class, for example, a fountain pen with a diameter of “1.7 cm” and the color “black”.
Java is primarily used to program web applications, desktop applications, and apps. For example, apps for Google’s Android operating system are developed in Java.

 

 

Steps to install Oracle Java 17 (JDK/JRE) on Ubuntu 20.04 |22.04 LTS

#1st Method using Tar file

1. Download Oracle Java 17 LTS Deb file

The Linux Deb binary to easily install Java 17 is available on the official website of Oracle, visit that. On the page either click on the Deb file to download it using the browser or simply right-click and copy its link. After that use wget in terminal to download the same.

sudo apt install wget -y

wget past-link

example:

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

 

Download Oracle Java 17 Debian binary

 

2. Install Oracle Java JDK 17 on Ubuntu 20.04 |22.04 LTS

Now, once the Debian package of the latest Java 17 is on your system, use the APT package manager to install it.

sudo apt install ./jdk-17_linux-x64_bin.deb

Output:

Reading package lists... Done
Building dependency tree
Reading state information... Done
Note, selecting 'jdk-17' instead of './jdk-17_linux-x64_bin.deb'
The following additional packages will be installed:
alsa-topology-conf alsa-ucm-conf libasound2 libasound2-data libbsd0 libc6-i386 libc6-x32 libfreetype6 libpng16-16
libx11-6 libx11-data libxau6 libxcb1 libxdmcp6 libxext6 libxi6 libxrender1 libxtst6 x11-common
Suggested packages:
libasound2-plugins alsa-utils

 

3. Inform system about new Oracle Java installation

As we have installed it manually, let the system know that we recently have added a new version of java at some particular directory or path. So, that it could recognize the same.

sudo update-alternatives --install "/usr/bin/java" "java" "/usr/lib/jvm/jdk-17/bin/java" 1

 

4. Set default Java on Ubuntu 20.04/22.04 (optional)

If you don’t want to set Oracle Java 17 as your system-wide default Java then you can skip this step. Otherwise, run the given command:

sudo update-alternatives --set java /usr/lib/jvm/jdk-17/bin/java

In the future, if you want to set some other version to be the default one then just change the folder path to Java binary as shown in the above command

 

5. Check the Oracle JDK/JRE version

Finally, to confirm the Oracle’s Java 17 is there run the given syntax:

java --version

Check the Oracle JDK JRE version ubuntu 20.04 LTS

 

6. Uninstall or remove

Well, if you don’t need this version of JAVA anymore then we can remove it using a simple command:

sudo apt purge jdk-17

————————————————————————————————————

#2nd method using PPA

Note: The PPA given here is not from Ubuntu or Oracle, instead of some third party or developer hence will not recommend for production systems. As we don’t know when the maintainer of the PPA would abandon it. However, the benefit of using PPA is you won’t have to update the Java manually in the future. Running system update and upgrade command will do that for you.

 

Add PPA repository for Oracle JDK 17 installer

Here is the command to add the PPA repository for Oracle JDK 17:

sudo apt install software-properties-common
sudo add-apt-repository ppa:linuxuprising/java -y

 

Run system update

To properly integrate the added PPA repository run the system update command once again:

sudo apt update

 

Command to Install JDK-17 on Ubuntu 20.04 | 22.04 Linux

Once the repository is added, let’s run the APT package manager command to install Oracle Java 17.

If you want to set this version as the default one after the installation- run this command

sudo apt install oracle-java17-installer --install-recommends

Whereas those who want to install Java 17 but do not want to set it as the default version can go for this one:

sudo apt install oracle-java17-installer --no-install-recommends

sudo apt install oracle java17 installer

Accept Terms

Configuring Oracle Java 17 installe ubuntu 20.04 or 22.04 Accept Oracle JAVA SE Terms

Check version:

java --version

 

To remove or delete it

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

Where to remove the PPA repo, use:

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

 

Other Articles:

Add repository to Install MySQL 5.7 on Ubuntu 20.04 LTS Linux
How to install MySQL 8.0 Server on Debian 11 Bullseye
Install VNC Server on Ubuntu 20.04 | 18.04
2 ways to install Chrome Browser on Ubuntu

 

 

Leave a Comment

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