Installing JDK on Debian 10

Java Development Kit or JDK in short is used to develop and run Java applications. There are two variants of JDK, a) OpenJDK and b) Oracle JDK. Oracle JDK is licensed under Oracle. OpenJDK is an open source implementation of JDK. Their license is very different. In this article, I am going to show you how to install OpenJDK and OracleJDK on Debian 10 Buster. So, let’s get started.

Installing OpenJDK:

OpenJDK (version 11) is available in the official package repository of Debian 10 Buster. So, you can install it very easily using the APT package manager.

First, update the APT package repository cache with the following command:

$ sudo apt update

The APT package repository cache should be updated.

There are two OpenJDK packages in the official package repository of Debian 10. OpenJDK and OpenJDK headless.

OpenJDK comes with graphics programming libraries by default. But, OpenJDK headless is meant to run in the server where there is no graphical user interface, thus it does not come with any graphics programming libraries. It is lightweight as well.

To install OpenJDK, run the following command:

$ sudo apt install openjdk-11-jdk

To install OpenJDK headless, run the following command:

$ sudo apt install openjdk-11-jdk-headless

Now, to confirm the installation, press Y and then press <Enter> to continue.

The APT package manager will download and install all the required packages. It will take a while to complete.

At this point, OpenJDK should be installed.

Now, check whether OpenJDK is working correctly with the following commands:

$ java -version
$ javac -version

As you can see, OpenJDK 11.0.4 is installed and it is working correctly.

Installing Oracle JDK:

If you want to install Oracle JDK, then all you have to do is download Oracle JDK and install it on Debian 10.

To download Oracle JDK, visit the official download page of Oracle JDK 12 (the latest version at the time of this writing). Once the page loads, click on Accept License Agreement to accept the Oracle Technology Network License Agreement.

Now, click on the JDK deb download link as marked in the screenshot below.

Your browser should prompt you to download the Oracle JDK deb file. Select Save File and click on OK.

The download should start. It may take a while to complete.

Once the download is complete, navigate to the ~/Downloads directory as follows:

$ cd ~/Downloads

You should find the file (jdk-12.0.2_linux-x64_bin.deb) that you just downloaded.

Now, update the APT package repository cache as follows:

$ sudo apt update

APT package repository cache should be updated.

Now, install the jdk-12.0.2_linux-x64_bin.deb package file with the following command:

$ sudo apt install ./jdk-12.0.2_linux-x64_bin.deb

The installation should start.

At this point, the installation should be complete.

Now, we have to find the path where the javac binary is installed. The DEB package file (jdk-12.0.2_linux-x64_bin.deb) name started with jdk-12.0.2. So, this is the package name.

To find the location of the javac binary file, run the following command:

$ dpkg –listfiles jdk-12.0.2 | grep bin/javac

As you can see, the path is /usr/lib/jvm/jdk-12.0.2/bin/javac. So, the JAVA HOME directory is /usr/lib/jvm/jdk-12.0.2 (Remember that).

The Oracle JDK DEB package does not add the JDK binaries to the PATH. So, we have to manually update the PATH environment variable of Debian 10.

To do that, create a shell script in /etc/profile.d directory with the following command:

$ sudo nano /etc/profile.d/

Now, add the following lines to the script:

export JAVA_HOME="/usr/lib/jvm/jdk-12.0.2"
export PATH="$PATH:${JAVA_HOME}/bin"

The final configuration file should look as shown in the screenshot below. Now, save the file by pressing <Ctrl> + X followed by Y and <Enter>.

Once the file is saved, restart your Debian 10 machine with the following command:

$ sudo reboot

Once your computer starts, check whether everything is working with the following commands:

$ java -version
$ javac -version

As you can see Oracle JDK 12.0.2 is installed and it’s working correctly.

So, that’s how you install OpenJDK and Oracle JDK on Debian 10 Buster. Thanks for reading this article.

ONET IDC thành lập vào năm 2012, là công ty chuyên nghiệp tại Việt Nam trong lĩnh vực cung cấp dịch vụ Hosting, VPS, máy chủ vật lý, dịch vụ Firewall Anti DDoS, SSL… Với 10 năm xây dựng và phát triển, ứng dụng nhiều công nghệ hiện đại, ONET IDC đã giúp hàng ngàn khách hàng tin tưởng lựa chọn, mang lại sự ổn định tuyệt đối cho website của khách hàng để thúc đẩy việc kinh doanh đạt được hiệu quả và thành công.
Bài viết liên quan

Tess4J Tutorial with Maven And Java

In today’s era when the data is ever growing, the people who deal with data everyday work mostly with unstructured textual...

How to Install Java 9 on Ubuntu

Java is not included in Ubuntu by default. There are many application that do not work without Java. So, you require to...

How to Install JDK 12 on Arch Linux

Java Development Kit (JDK) is used to compile, run, debug, and sign Java applications. It is used by Java developers all...