How to Install Oracle Java Development Kit (JDK) on Debian 12

The full form of Oracle JDK is Oracle Java Development Kit. Oracle JDK is used to compile the Java source code and test the Java programs. So, if you’re a Java Developer or you want to learn Java on Debian 12, you might want to install Oracle JDK on Debian 12.

In this article, we will show you how to download and install Oracle Java Development Kit (JDK) on Debian 12 “Bookworm”.

NOTE: If you’re looking to install OpenJDK and OpenJRE on Debian 12, read the article on How to Install Java OpenJDK and OpenJRE on Debian 12.

Topic of Contents:

  1. Downloading Oracle Java Development Kit (JDK) for Debian 12
  2. Installing Oracle Java Development Kit (JDK) on Debian 12
  3. Adding Oracle Java Development Kit (JDK) to the Path of Debian 12
  4. Checking Whether Oracle Java Development Kit (JDK) Is Working
  5. Conclusion

Downloading Oracle Java Development Kit (JDK) for Debian 12

To download Oracle Java Development Kit (JDK) for Debian 12, visit https://www.oracle.com/java/technologies/downloads/ from your favorite web browser.

Once the page loads, select the version of Oracle JDK that you want to download[1]. At the time of this writing, you can download Oracle JDK 17 and 20 from the official website of Oracle JDK.

Once you decided on the version of Oracle JDK that you want to download, click on the x64 Debian Package download link of Oracle JDK from the Linux tab[2] as marked in the following screenshot[3]:

A screenshot of a computer Description automatically generated

Your browser should start downloading the Oracle JDK Debian package file. It takes a while to complete.

A screenshot of a computer Description automatically generated

At this point, the Oracle JDK Debian package file should be downloaded.

A screenshot of a computer Description automatically generated

Installing Oracle Java Development Kit (JDK) on Debian 12

The Oracle JDK Debian package file should be downloaded in the ~/Downloads directory of your Debian 12 machine.

Before installing the Oracle JDK Debian package file on Debian 12, update the Debian 12 package database cache with the following command:

A screenshot of a computer Description automatically generated

To install the Oracle JDK Debian package file on Debian 12, run the following command:

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

To confirm the installation, press Y and then press <Enter>.

A screenshot of a computer Description automatically generated

The Oracle JDK Debian package file is being installed. It takes a few seconds to complete.

A screenshot of a computer Description automatically generated

At this point, Oracle JDK should be installed on Debian 12.

A screenshot of a computer Description automatically generated

Adding Oracle Java Development Kit (JDK) to the Path of Debian 12

Once Oracle JDK is installed on your Debian 12 machine, you have to add it to the PATH of Debian 12 to access it.

First, find the directory where Oracle JDK is installed with the following command:

$ ls -d /usr/lib/jvm/jdk*

As you can see, the Oracle JDK installation directory in our case is /usr/lib/jvm/jdk-20. It may be different for you depending on the version of Oracle JDK that you installed. So, make sure to replace this directory path with yours.

A screenshot of a computer Description automatically generated

Create a new file which is “jdk-20.sh” (if you installed Oracle JDK 20. Otherwise, replace 20 with the Oracle JDK version that you installed) in the /etc/profile.d/ directory and open it with the nano text editor.

$ sudo nano /etc/profile.d/jdk-20.sh

Type in the following lines in the “jdk-20.sh” file and press <Ctrl> + X followed by Y and <Enter> to save the changes.

export JAVA_HOME=“/usr/lib/jvm/jdk-20”

export PATH=$PATH:${JAVA_HOME}/bin”

A screenshot of a computer Description automatically generated

For the changes to take effect, reboot your computer with the following command:

Once your Debian 12 machine boots, you should see that the JAVA_HOME environment variable is set correctly and Oracle JDK is in the PATH environment variable of Debian 12.

$ echo $JAVA_HOME

$ echo $PATH

A screenshot of a computer Description automatically generated

Checking Whether Oracle Java Development Kit (JDK) Is Working

Once Oracle JDK is installed, run the following commands to check whether you can access Oracle JDK from the terminal:

$ javac –version

$ java –version

As you can see, the Oracle JDK compiler version 20 and Oracle JDK runtime environment version 20 are installed on our Debian 12 machine.

A screenshot of a computer Description automatically generated

Conclusion

We showed you how to download Oracle JDK for Debian 12. We also showed you how to install Oracle JDK on Debian 12 and how to add Oracle JDK to the path of Debian 12 and access it as well.

source

Leave a Comment