How to install Oracle Java 8 on Debian 9

Oracle Java 8 required by some programs and it is not available on Debian archive due to licensing issues.

To install Java 8 on Debian Stretch with minimum effort, you can use WebUpd8’s Java PPA repositories. Follow the steps below:

$ sudo apt-key adv --keyserver --recv-keys EEA14886
$ sudo add-apt-repository "deb trusty main"

$ sudo apt update
$ sudo apt-get install oracle-java8-installer

If there are other Java/JDK packages on your system, you need to select the default one. Selection can be made with update-alternatives command but WebUpd8 repositories also includes a small package which makes setting Java 8 as default more easily. You just need to install the oracle-java8-set-default package:

$ sudo apt install oracle-java8-set-default

You can also verify the selection with update-alternatives --config java command:

$ sudo update-alternatives --config java
There are 2 choices for the alternative java (providing /usr/bin/java).

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