How to Install Oracle Java JDK 18 on Debian and Ubuntu

“After reading this tutorial, you will be able to install both Oracle Java JDK and OpenJDK on Debian and based Linux distributions, including Ubuntu. The process also includes instructions to add the JAVA HOME path.”

This tutorial explains how to install Oracle Java JDK 18 on Debian-based Linux distributions easily.

This document is optimized both for users looking for fast instructions to implement and for users looking for theoretical knowledge. For practical purposes, theoretical content was placed at the end of the instructions.

All steps described in this tutorial contain screenshots, making it easy for every Linux user to follow them independently of their expertise level.

Installing Oracle Java JDK 18 on Debian or Ubuntu

Note: Before starting with the installation process, in my particular case, I got a dependency error when installing JDK. Probably it will not happen on your computer, but just in case you lack the same dependency, run the following command.

sudo apt install libc6-x32

To begin installing JDK 18, visit the link https://www.oracle.com/java/technologies/downloads/, scroll down the page and find the tab with the JDK version you want.

Find the proper package for your system. In our case, we will download the .deb package, which is compatible with Debian/Ubuntu dpkg packages manager.

As you can see, there are also available rpm packages and sources for other Linux distributions and operating systems.

Once the .deb package is downloaded, run it using the dpkg command followed by the -i option, as shown below.

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

Now JDK 18 is properly installed in your Debian/Ubuntu system.

To make Java accessible to other applications, you need to export the Java_home. If using Oracle JDK, run the commands below.

export JAVA_HOME=/usr/lib/jvm/jdk-18/

And

export PATH=$JAVA_HOME/bin:$PATH

This will work only for the current session. To make the path permanent, add the following line to the /etc/profile file.

JAVA_HOME="/usr/lib/jvm/jdk-18/"

To remove JDK 18, just run:

sudo dpkg -r jdk-18

Installing OpenJDK in Debian and Ubuntu

OpenJDK can be installed through the apt packages manager.

sudo apt install openjdk-17-jre

Also, install the default-jdk package, as shown in the following figure.

sudo apt-get install default-jdk -y

Now OpenJDK is installed. You can export the path by running the commands shown below.

export JAVA_HOME=java-17-openjdk-amd64/

And

export PATH=$PATH:$JAVA_HOME/bin

Installing Oracle JDK on Red Hat

To install JDK on Red Hat-based Linux distributions, download the RPM package from the previous link (https://www.oracle.com/java/technologies/downloads/)

After downloading it, run the following command.

sudo rpm -ivh jdk-18_linux-x64_bin.rpm

For additional instructions to install JDK on other systems, visit the following links:

About Java and JDK

Java is a simple, object-oriented high-level programming language. It features multi-thread, neutral architecture, high performance, and security, among other characteristics.

The JAVA Development Kit to program Java applications is what you need to create your own applications; you can find a tutorial to start programming Java at https://docs.oracle.com/javase/tutorial/getStarted/cupojava/index.html.

JDK vs. OpenJDK

The main difference between OpenJDK and JDK is the same difference between most free open-source programs and their closed-coded counterparts.

JDK is a paid license and is not open-source; users can’t modify it. OpenJDK is open source and well supported by the community; users can modify it and contribute to its development.

JDK is still free for testing purposes, but costs and the improvement of the free alternative are increasing the OpenJDK public.

OpenJDK is licensed under GPL, which guarantees users the right to execute, study, modify, and share. Both codes are pretty similar.

Installing Debian Packages (dpkg)

The dpkg command with the -i (–install) option used in this tutorial is common to install .deb packages in Debian or similar distributions like Ubuntu. The removal instructions section shows that you can remove installed packages using dpkg with the -r flag followed by the package name.

Dpkg is Debian and based distribution packages manager. It has additional functions to package installation and removal, like printing information on installed programs. For example, to show if JDK is installed on the system and details, you can use dpkg with the -s flag.

Installing Debian (apt)

The apt command used to install OpenJDK is a frontend for dpkg. Its main advantage is apt fetches the software from repositories and resolves dependencies automatically.

Removing packages using apt can be done with the remove option or the purge option if you want to remove configuration files.

Conclusion

As you can see, installing both OpenJDK and Oracle Java JDK 18 on Debian and Ubuntu is an easy task, just as installing any other .deb package.

The simplicity is the same for Red Hat Linux-based distributions. Users only need to know dpkg or rpm basics. This can be done by any Linux user independently of their experience level. Java is a potent language recommended for people getting introduced to programming.

You can use the previous instructions to install any JDK version you want; just replace version numbers. The download link contains old alternative versions available for download.

You also can install the last OpenJDK version manually by executing the .deb package.

I hope this tutorial explaining how to install Oracle Java 18 JDK on Debian and its Linux distributions was useful. Keep following Linux Hint for additional Linux tutorials and tips.



from https://ift.tt/HX2RTA5

Post a Comment

0 Comments