How to Install Java On Debian 8/9/10

Java is one of the most popular programming languages used to build different kinds of applications and systems. Applications developed in Java are scalable, flexible and maintainable.

In this article ,we`ll explain how to install Java(OpenJDK or Oracle Java) on Debian Linux system.

Oracle Java Licensepermits only non-commercial use of the software, such as personal use and development use.

The default Debian 10 repositories include OpenJDK 11 packages.

Step 1. Install OpenJDK on Debian

First,update the packages index and install the OpenJDK 11 JDK package.type the following command:

sudo apt update
sudo apt install default-jdk

JRE is included in the JDK package. If you need only JRE, install the default-jrepackage.

Once the installation is complete, you can verify it by checking the Java version:

java -version

The output will look something like this:

openjdk version "11.0.3" 2019-04-16
OpenJDK Runtime Environment (build 11.0.3+7-post-Debian-5)
OpenJDK 64-Bit Server VM (build 11.0.3+7-post-Debian-5, mixed mode, sharing)

Now,you have successfully installed Java on your Debian system.

Step 2. Install Oracle Java on Debian

The following steps describe how to install Oracle Java 11 on Debian.

Import the PPA public key and enable the repository with the following command:

sudo apt-key adv --keyserver hkp:// --recv-keys 73C3DB2A
echo 'deb bionic main' | sudo tee /etc/apt/sources.list.d/linuxuprising-java.list

Once the repository is added, update the packages list and install the oracle-java11-installer package by typing:

sudo apt update
sudo apt install oracle-java11-installer

You will be prompted to accept the Oracle license.

Verify the installation by running the following command which will print the R version:

java -version
openjdk version "11.0.3" 2019-04-16
OpenJDK Runtime Environment (build 11.0.3+1-Debian-1bpo91)
OpenJDK 64-Bit Server VM (build 11.0.3+1-Debian-1bpo91, mixed mode, sharing)

Step 3. Set the default JDK version

If you have multiple Java versions installed on your Debian system you can check what version is set as the default one by typing the following command:

java -version

To change the default version use the update-alternativescommand:

sudo update-alternatives --config java

The output should look something like this:

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/adoptopenjdk-8-hotspot-amd64/bin/java   1081      manual mode
  2            /usr/lib/jvm/java-11-openjdk-amd64/bin/java          1111      manual mode

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

You will be presented with a list of all installed Java versions. Enter the number of the version you want to be used as the default and press Enter.

Step 4. Configure Environment Variable

To find where Java is installed use sudo update-alternatives --config java command.

sudo update-alternatives --config java

Edit the /etc/environment file, typing the following command:

sudo vim /etc/environment

/etc/environment is a system-wide configuration file, which is used by all users. If you want to set the JAVA_HOME variable on a per-user basis then add the line to the .bashrc or any other configuration file which is loaded when the user logs in.

If you want to set JAVA_HOME to the OpenJDK 11 path add the following line, at the end of the file /etc/environment:


For changes to take effect use the source command:

source /etc/environment

Verify that the JAVA_HOME environment variable was correctly ,type the following command:


You should see the path to the Java installation:


Step 5. Uninstall Java

You can uninstall Java package installed with apt command.

For example, to uninstall the default-jdk package,type the following command:

sudo apt remove default-jdk


In this article,You have learned how to install Java on your Debian linux can try it on you Debian linux Server.If you have any questions or thoughts to share, don’t forget to leave a comment to reach us.

Leave a Reply