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


Install Oracle Java JDK on Debian 11 are needed for a variety of software applications, including Cassandra, Glassfish, Tomcat, Jetty, and Jenkins.

This guide will show you how to Install Oracle Java JDK on Debian 11. We will install Oracle’s regular JDK along with OpenJDK. After that, you can decide which version to use for your projects. Once finished, you can use the Java Runtime to run applications or the Java Development Kit (JDK) to build programs.


To finish this tutorial, you will require:

One Debian 11 server with a non-root user who has sudo enabled. To get this installed, use our first Debian 11 server setup tutorial.

Step 1 — Installing Java:

The JDK, which provides software tools for developers like a compiler and debugger, the JRE, which executes Java programs, and two primary Java installation options—OpenJDK, an open-source Java implementation included with Debian, and Oracle JDK, the original Java version that is fully maintained by Oracle, the Java developers—are the two main components of installing Java.

Oracle has acknowledged both of these versions formally. Both are produced by Oracle, however OpenJDK gains from community contributions as well because it is an open-source project. However as of Java 11, the two systems are now functionally identical, according to Oracle. whatever license to install will depend on whatever you choose as the one that best suits your needs. Moreover, OracleJDK comes with the JRE installed, but OpenJDK lets you install it separately.

Option 1—Installing the Default JRE/JDK:

One approach to install it is to use the version of Java that comes with the Debian package. Debian 11 is pre-installed with OpenJDK version 11, an open-source JRE and JDK variation compatible with Java 11. Java 11 is the most recent Long Term Support version.

Execute the following command to Install Oracle Java JDK on Debian 11:

  1. sudo apt install default-jre

The JRE will allow you to run almost all Java software.

Verify the installation with the following:

  1. java -version

The following output will return:

openjdk version "11.0.16" 2022-07-19
OpenJDK Runtime Environment (build 11.0.16+8-post-Debian-1deb11u1)
OpenJDK 64-Bit Server VM (build 11.0.16+8-post-Debian-1deb11u1, mixed mode, sharing)

Some Java-based software may require the JDK in addition to the JRE for compilation and operation. Use the following command to install the JDK and the JRE at the same time:

  1. sudo apt install default-jdk

Verify that the JDK is installed by checking the version of javac, the Java compiler:

  1. javac -version

You’ll receive the following output:

javac 11.0.16

Next, you will learn how to install Oracle’s official JDK and JRE.

Option 2 — Installing Oracle JDK 11

Oracle’s licensing agreement for Java doesn’t enable automatic installation through package managers. You must first register for an Oracle account, download the JDK manually, then add a new package repository for the version you want to use in order to install the official Oracle JDK. Then, with the aid of an independent installation script, you can utilize apt to install it. The JRE is preinstalled with Oracle JDK, therefore you don’t need to install it separately.

The installation script’s version and the Oracle JDK version you need to download must match. Get the version you require by going to the Oracle Java 11 Installer website. Your package can be found in the following figure:

The Oracle Java installer web page listing all the currently available packages

This image has a script version of 11.0.13. Oracle JDK 11.0.13 is therefore necessary. The version number may vary depending on when you install the app. You don’t need to download anything from this page because you will shortly be receiving the installation script through apt.

Next, go to the Archive Downloads and locate the version that matches the one you need.

The Oracle Java archive downloads web page where you can find versions of Java that are not the latest release.

From this list, choose the Linux x64 compressed archive .tar.gz package:

The Oracle Java 11.0.13 download webpage. Selected is the Linux x64 Compressed Archive file.

  1. A screen asking you to accept the Oracle licensing agreement will appear. To accept the licensing agreement, check the box and click the “Download” button. The download will start now. Before the download begins, you might need to connect into your Oracle account one again.After the file has finished downloading, you must move it to your server. Upload the file to your server from your local PC. Using the Windows Subsystem for Linux on macOS, Linux, or Windows, move the file to your Sammy user’s home directory using the scp command. Assuming you have the Oracle JDK file saved in the Downloads folder on your local computer, run the following command:scp Downloads/jdk-11.0.13_linux-x64_bin.tar.gz sammy@your_server_ip:~
  1. After the file has finished uploading, go back to your server and add the third-party repository that will assist you in installing Java from Oracle.Import the signing key that was used to confirm the installation of the software first:sudo gpg –keyserver –recv-keys –homedir /tmp –no-default-keyring –keyring /usr/share/keyrings/oracle-jdk11-installer.gpg AC08CACC073C3DB2A

You’ll receive the following output:

gpg: keybox '/usr/share/keyrings/oracle-jdk11-installer.gpg' created
gpg: /tmp/trustdb.gpg: trustdb created
gpg: key EA8CACC073C3DB2A: public key "Launchpad PPA for Linux Uprising" imported
gpg: Total number processed: 1
gpg:           	imported: 1

Next, add the repository to your list of package sources:

  1. echo “deb [arch=amd64 signed-by=/usr/share/keyrings/oracle-jdk11-installer.gpg] jammy main” | sudo tee /etc/apt/sources.list.d/oracle-jdk11-installer.list > /dev/null

Update your package list to make the new software available for installation:

  1. sudo apt update

The installer will look for the Oracle JDK you downloaded in /var/cache/oracle-jdk11-installer-local. First create this directory:

  1. sudo mkdir -p /var/cache/oracle-jdk11-installer-local/

Then, move the Oracle JDK archive there:

  1. sudo cp jdk-11.0.13_linux-x64_bin.tar.gz /var/cache/oracle-jdk11-installer-local/

Finally, install the package:

  1. sudo apt install oracle-java11-installer-local

The installer will first ask you to accept the Oracle license agreement. Accept the agreement, and then the installer will extract the Java package and install it.

Now, you will learn how to select the version of Java you want to use.

Step 2—Managing Java

On a single server, several Java installs are possible. Using the update-alternatives command, you can set which version is the default for usage on the command line:

  1. sudo update-alternatives –config java

This is the following output if you’ve installed both versions of Java in this tutorial:

There are 2 choices for the alternative java (providing /usr/bin/java).

  Selection    Path                                         Priority   Status
  0            /usr/lib/jvm/java-11-openjdk-amd64/bin/java   1111      auto mode
  1            /usr/lib/jvm/java-11-openjdk-amd64/bin/java   1111      manual mode
* 2            /usr/lib/jvm/java-11-oracle/bin/java          1091      manual mode

Press <enter> to keep the current choice[*], or type selection number:

Choose the number associated with the Java version to use it as the default, or press ENTER to leave the current settings in place.

You can do this for other Java commands, such as the compiler (javac):

  1. sudo update-alternatives –config javac

Other commands for which this command can be run include, but are not limited to: keytooljavadoc, and jarsigner.

Step 3 — Setting the Environment Variable

Many programs written in Java use the environment variable to determine which Java installation location.

To set this environment variable, first determine where Java is installed. Use the update-alternatives command:

  1. sudo update-alternatives –config java

This output will list each installation of Java along with its installation path:

  Selection    Path                                         Priority   Status
  0            /usr/lib/jvm/java-11-openjdk-amd64/bin/java   1111      auto mode
  1            /usr/lib/jvm/java-11-openjdk-amd64/bin/java   1111      manual mode
* 2            /usr/lib/jvm/java-11-oracle/bin/java          1091      manual mode

In this case, the installation paths are as follows:

  • Oracle Java 11 is located at /usr/lib/jvm/java-11-oracle/bin/java.
  • OpenJDK 11 is located at /usr/lib/jvm/java-11-openjdk-amd64/bin/java.

These paths show the path to the java executable.

Next, copy the path for your preferred installation, excluding the trailing bin/java component. Then open /etc/environment using nano or your preferred text editor:

  1. sudo nano /etc/environment

At first, this file can be empty. Add the following line at the end of the file, being careful to omit the bin/part of the path and substitute your own copied path for the highlighted path:

Environment /etc

JavaHome: “/usr/lib/jvm/java-11-openjdk-amd64”

All users on your system will have their Java_HOME path set if you modify this file.

After saving the file, close the editor. To accomplish this with nano, hit CTRL + X, Y, and then Enter.

To apply the modifications to your current session, refresh this file now:

/etc/environment as the source

Check to see if the environment variable is defined:


You will see the path you previously set in your output:

/usr/lib/jvm/java-11-openjdk-amd64 is the output.

To apply this setting, other users must run the command source /etc/environment or log out and back in.


During this session, you learned how to maintain several Java versions that you installed. Installing Java-based apps such as Cassandra, Glassfish, Tomcat, Jetty, and Jenkins is now possible.


Get more inforamtion about

How to Install Virtualbox Pack on Linux step_by_step guide

Leave a Reply

Your email address will not be published. Required fields are marked *