How to Install Oracle JAVA 8 on Debian 9 / Debian 8


Today we will be going through the installation of Oracle Java SDK 1.8_u171 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 SDK

You can download JDK using either command line or browser to download. Better use the browser to download the Oracle SDK 8.

Want to download Oracle Java 8 on the terminal, run:

### 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-8u*-linux-*.tar.gz

#  mv jdk1.8.*/ /usr/

Install Oracle Java 8

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

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

# 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/jdk1.8.0_162/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/jdk1.8.0_152/bin/java to provide /usr/bin/java (java) in manual mode

Verify the Java

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

# java –version


java version "1.8.0_181"
Java(TM) SE Runtime Environment (build 1.8.0_181-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.181-b13, 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.

# export JAVA_HOME=/usr/jdk1.8.0_*

# export JRE_HOME=/usr/jdk1.8.0_*/jre/

Set PATH variable too.

# export PATH=$JAVA_HOME/bin:$PATH

To set it as a 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 8 on Debian 9 / Debian 8