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:
- Downloading Oracle Java Development Kit (JDK) for Debian 12
- Installing Oracle Java Development Kit (JDK) on Debian 12
- Adding Oracle Java Development Kit (JDK) to the Path of Debian 12
- Checking Whether Oracle Java Development Kit (JDK) Is Working
- 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]:
Your browser should start downloading the Oracle JDK Debian package file. It takes a while to complete.
At this point, the Oracle JDK Debian package file should be downloaded.
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.
$ ls -lh
Before installing the Oracle JDK Debian package file on Debian 12, update the Debian 12 package database cache with the following command:
To install the Oracle JDK Debian package file on Debian 12, run the following command:
To confirm the installation, press Y and then press <Enter>.
The Oracle JDK Debian package file is being installed. It takes a few seconds to complete.
At this point, Oracle JDK should be installed on Debian 12.
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:
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.
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.
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 PATH="$PATH:${JAVA_HOME}/bin"
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 $PATH
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:
$ 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.
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.