Objective

The objective is to install Oracle Java SE Development Kit on Debian 9 Stretch Linux

Operating System and Software Versions

  • Operating System: - Debian 9 Stretch Linux
  • Software: - Oracle Java JDK 1.8.0_131 ( at the time of writing )

Requirements

Privileged access to your Debian 9 Stretch Linux may be required for Oracle Java SE Development Kit system-wide installation.

Difficulty

EASY

Conventions

  • # - requires given linux commands to be executed with root privileges either directly as a root user or by use of sudo command
  • $ - requires given linux commands to be executed as a regular non-privileged user

Instructions

Download Oracle Java SE Development Kit

First step is to use your browser to download Oracle Java SE Development Kit from the official Oracle website. Alternatively, if you do not have access to GUI your can download Oracle Java SE Development Kit from the command line using curl command.

NOTE: The URLs used below to download Oracle Java SE Development Kit may be outdated, so please update where necessary.

Retrieve 64bit Oracle Java SE Development Kit tarball URL using curl command. If curl is not yet available on your system you can install by # apt install curl:


$ curl -s http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html | grep "otn-pub" | cut -d \" -f12 | grep linux-x64.tar.gz
http://download.oracle.com/otn-pub/java/jdk/8u131-b11/d54c1d3a095b4ff2b6607d096fa80163/jdk-8u131-linux-x64.tar.gz
Next,use the above URL from curl's output do download the actual Oracle Java SE Development Kit tarball:
$ curl -LOb "oraclelicense=a" http://download.oracle.com/otn-pub/java/jdk/8u131-b11/d54c1d3a095b4ff2b6607d096fa80163/jdk-8u131-linux-x64.tar.gz
If all went well the Oracle Java SE Development Kit tarball should be available within your current working directory:
$ ls
jdk-8u131-linux-x64.tar.gz

Install and Configure

At this stage we will extract the previously downloaded package into /opt/java-jdk directory and make is default system-wide:
# mkdir /opt/java-jdk
# tar -C /opt/java-jdk -zxf jdk-8u131-linux-x64.tar.gz
Next, use update-alternatives command to make it default on your Debian stretch system:
# update-alternatives --install /usr/bin/java java /opt/java-jdk/jdk1.8.0_131/bin/java 1
# update-alternatives --install /usr/bin/javac javac /opt/java-jdk/jdk1.8.0_131/bin/javac 1

Confirm Install

The Oracle SE Development Kit should now be default on your system. To confirm, query java's version:
$ java -version
java version "1.8.0_131"
Java(TM) SE Runtime Environment (build 1.8.0_131-b11)
Java HotSpot(TM) 64-Bit Server VM (build 25.131-b11, mixed mode)
ARE YOU LOOKING FOR A LINUX JOB?
Submit your RESUME or create a JOB ALERT on LinuxCareers.com job portal.
DO YOU NEED ADDITIONAL HELP?
Get extra help by visiting our LINUX FORUM or simply use comments below.

You may also be interested in: