How To Install Oracle JAVA JDK 11 / 8 on Debian 9 / Debian 8


Today we will be going through the installation of Oracle Java JDK 11 / 8 on Debian 9. Java SDK is the most important one for the developers, and this guide will be more useful for them to build development environment when they especially use Debian.

Switch to the root user.

sudo su-


su -

Download Java JDK

You can download JDK using either command line or browser to download.

Oracle Java 11:

wget --no-check-certificate --no-cookies --header "Cookie: oraclelicense=accept-securebackup-cookie"

Oracle Java 8:

### 32 bit ###

wget --no-check-certificate --no-cookies --header "Cookie: oraclelicense=accept-securebackup-cookie"

### 64 Bit ###

wget --no-check-certificate --no-cookies --header "Cookie: oraclelicense=accept-securebackup-cookie"

Extract the downloaded JDK archive to the desired directory (Ex. /usr/)

tar -zxvf jdk-*

mv jdk* /usr/

Install Oracle Java

Once you moved the java to the location you want, then you must run update-alternatives commands to install the Java on your system.

### Oracle Java 11 ###

update-alternatives --install /usr/bin/java java /usr/jdk-11.*/bin/java 2

### Oracle Java 8 ###

update-alternatives --install /usr/bin/java java /usr/jdk1.8.*/bin/java 2

Set the default java using the below command.

update-alternatives --config java

Select the Oracle Java

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

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

  Selection    Path                                            Priority   Status
* 0            /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java   1081      auto mode
  1            /usr/jdk-11.0.1/bin/java                         2         manual mode
  2            /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java   1081      manual mode

Press  to keep the current choice[*], or type selection number: 1
update-alternatives: using /usr/jdk-11.0.1/bin/java to provide /usr/bin/java (java) in manual mode

If you require Oracle Java JDK 11, then choose the 1 and press enter.

Verify Java

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

java –version


Oracle Java 11:

java version "11.0.1" 2018-10-16 LTS
Java(TM) SE Runtime Environment 18.9 (build 11.0.1+13-LTS)
Java HotSpot(TM) 64-Bit Server VM 18.9 (build 11.0.1+13-LTS, mixed mode)

Oracle Java 8:

java version "1.8.0_191"
Java(TM) SE Runtime Environment (build 1.8.0_191-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.191-b12, mixed mode)

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 11:

export PATH=$PATH:/usr/jdk-11.0.1/bin
export JAVA_HOME=/usr/jdk-11.0.1
export J2SDKDIR=/usr/jdk-11.0.1

Oracle Java 8:

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

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

That’s All. Hope this post helped you install Oracle Java on Debian 9.

Further Reading

You might also like

How To Install Oracle JAVA JDK 11 / 8 on Debian 9 / Debian 8