How To Install Oracle Java JDK 12 / 11 / 8 on Debian 10 / Debian 9


Today we will be going through the installation of Oracle Java SE which includes Java Development Kit (JDK) and Java Runtime Environment (JRE) on Debian 10 / Debian 9.

Java JDK is the most important one for the developers, and this guide will be more useful for them to build a development environment when they especially use the Debian operating system.


To be able to install Oracle Java JDK, you need to log in as a user with sudo privileges.

Download Oracle Java

You can either use command line or browser to download the Java SE. Better use the browser as the command-line link may change when the new version is released.

Visit the Oracle Java SE page to download.

Oracle offers both .deb package and tarball for Oracle JDK 12 / 11 and only tarball for Oracle JDK 8 installation. So, I request you to download .deb package for Oracle JDK 12 / 11 and tarball for Oracle JDK 8 installation.

Oracle JDK 12:

Download Oracle JDK 12 (v12.0.2)

Oracle JDK 11 (LTS):

Download Oracle JDK 11 (v11.0.4) (Login Required)

Oracle JDK 8:

Download Oracle JDK 8 (v8u221) (Login Required)

If you still want to use the command line, use the below command.

### Oracle JDK 12 ###
wget --no-check-certificate --no-cookies --header "Cookie: oraclelicense=accept-securebackup-cookie"
### Oracle JDK 11 ###
### Oracle JDK 8 ###

Install Oracle Java

Depending on the type of package and the version you have download, execute the command to install or extract Oracle Java.

### Oracle JDK 12 ###
sudo apt install ./jdk-12.0.2_linux-x64_bin.deb
### Oracle JDK 11 ###
sudo apt install ./jdk-11.0.4_linux-x64_bin.deb
### Oracle JDK 8 ###
sudo tar -zxvf jdk-8u221-linux-x64.tar.gz -C /usr/lib/jvm/

Now, run update-alternatives command to install the Java on the system.

### Oracle JDK 12 ###
sudo update-alternatives --install /usr/bin/java java /usr/lib/jvm/jdk-12.0.2/bin/java 1
### Oracle JDK 11 ###

sudo update-alternatives --install /usr/bin/java java /usr/lib/jvm/jdk-11.0.4/bin/java 2
### Oracle JDK 8 ###
sudo update-alternatives --install /usr/bin/java java /usr/lib/jvm/jdk1.8.0_221/bin/java 3

Set Default Java Version

Set the default java using the below command.

sudo update-alternatives --config java

If the system has multiple versions of JAVA, then the above command may list it all, like below.

Change the default Java version by typing number under Selection column and then press enter.

Install Oracle JDK on Debian 10 - Set Default Java Version
Install Oracle JDK on Debian 10 – Set Default Java Version

Here, I chose to have Oracle JDK 11 as the default Java version on the system.

Verify Java Version

Once you have set up the alternatives, then check the java version using the following command.

java -version


java version "11.0.4" 2019-07-16 LTS
Java(TM) SE Runtime Environment 18.9 (build 11.0.4+10-LTS)
Java HotSpot(TM) 64-Bit Server VM 18.9 (build 11.0.4+10-LTS, mixed mode)
Java Version
Java Version

The output will vary depending upon the version of Oracle Java installation.

Setup Environmental Variable

Some Java application installations require prior configuration of environmental variables like JAVA_HOME, JRE_HOME, etc. So, you can set the environmental variables like below.

Oracle Java 12:

export PATH=$PATH:/usr/lib/jvm/jdk-12.0.2/bin
export JAVA_HOME=/usr/lib/jvm/jdk-12.0.2/
export J2SDKDIR=/usr/lib/jvm/jdk-12.0.2/

Oracle Java 11:

export PATH=$PATH:/usr/lib/jvm/jdk-11.0.4/bin
export JAVA_HOME=/usr/lib/jvm/jdk-11.0.4/
export J2SDKDIR=/usr/lib/jvm/jdk-11.0.4/

Oracle Java 8:

export PATH=$PATH:/usr/lib/jvm/jdk1.8.0_221/bin
export JAVA_HOME=/usr/lib/jvm/jdk1.8.0_221/
export JRE_HOME=/usr/lib/jvm/jdk1.8.0_221/jre/
export J2SDKDIR=/usr/lib/jvm/jdk1.8.0_221/
export J2REDIR=/usr/lib/jvm/jdk1.8.0_221/jre/

To set the environment variables permanent, place the above variables in the /etc/profile/ (All Users) or ~/.bash_profile (Single User) file.


That’s All. Hope this post helped you install Oracle Java on your Debian 10 / Debian 9. Java is a must to run applications such as Tomcat, Gradle, ELK Stack, Graylog, Eclipse IDE, etc.

Share your feedback in the comments section.

You might also like