“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.
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.
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.
This will work only for the current session. To make the path permanent, add the following line to the /etc/profile file.
To remove JDK 18, just run:
Installing OpenJDK in Debian and Ubuntu
OpenJDK can be installed through the apt packages manager.
Also, install the default-jdk package, as shown in the following figure.
Now OpenJDK is installed. You can export the path by running the commands shown below.
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.
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.
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.