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


Today we will be going through the installation of Oracle Java JDK on 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 Debian.


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 JDK, better to use the browser, the easiest one.

Visit the Oracle JDK page to download.

Oracle Java JDK 12:

Download Oracle JDK 12 (v12.0.1)

Oracle Java JDK 11 (LTS):

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

Oracle Java JDK 8:

Download Oracle JDK 8 (v8u211) (Login Required)

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

### Oracle Java JDK 12 ###

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

### Oracle Java JDK 11 ###


### Oracle Java JDK 8 ###


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

tar -zxvf jdk-*

sudo 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 12 ###

sudo update-alternatives --install /usr/bin/java java /usr/jdk-12.*/bin/java 1

### Oracle Java 11 ###

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

### Oracle Java 8 ###

sudo update-alternatives --install /usr/bin/java java /usr/jdk1.8.*/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.

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-12.0.1/bin/java                         1         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-12.0.1/bin/java to provide /usr/bin/java (java) in manual mode

If you require Oracle Java JDK 12, then choose the 1 (number in selection column) and press enter.

Verify Java Version

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

java -version


java version "12.0.1" 2019-04-16
Java(TM) SE Runtime Environment (build 12.0.1+12)
Java HotSpot(TM) 64-Bit Server VM (build 12.0.1+12, mixed mode, sharing)

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/jdk-12.0.1/bin
export JAVA_HOME=/usr/jdk-12.0.1
export J2SDKDIR=/usr/jdk-12.0.1

Oracle Java 11:

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

Oracle Java 8:

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

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


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

You might also like