How To Install Oracle Java JDK 11 / 8 on Ubuntu 16.04 / Linux Mint 18

5

As already you know, Canonical no longer redistribute Oracle Java packages due to license issue. Canonical has removed the Java packages from their repository, and now they distribute OpenJDK as an alternative.

If you need Oracle Java on Ubuntu; you must do the installation through an external repository.

Here is the tutorial on installing Java JDK 11 / 8 on Ubuntu 16.04.

Install Oracle Java JDK 11 / 8 on Ubuntu 16.04 / Linux Mint 18

Open a terminal ( Ctrl + Alt + T ) and add the PPA repository.

### Oracle JDK 11 ### 

sudo add-apt-repository ppa:linuxuprising/java

### Oracle JDK 8 ###

sudo add-apt-repository -y ppa:webupd8team/java

Run the following command to pull the packages information from the newly added repository.

sudo apt-get update

Issue the following command to install Java JDK.

### Oracle JDK 11 ###

sudo apt-get install -y oracle-java11-installer

### Oracle JDK 8 ###

sudo apt-get install -y oracle-java8-installer

During the installation, you may need to accept the Oracle binary licenses.

To set the default Java, install the below packages according to the requirement.

### Oracle JDK 11 ###

sudo apt-get install -y oracle-java11-set-default

### Oracle JDK 8 ###

sudo apt-get install -y oracle-java8-set-default

Verify Java

java -version

Output:

JDK 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)

JDK 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 JAVA Environmental Variables

Some Java application installations require prior configuration of environmental variables like JAVA_HOME , JRE_HOME,etc.

To set JAVA environment variables, create a new file under /etc/profile.d directory.

sudo nano /etc/profile.d/javajdk.sh

Place the below variables based on the JDK version.

JDK 11:

export PATH=$PATH:/usr/lib/jvm/java-11-oracle/bin
export JAVA_HOME=/usr/lib/jvm/java-11-oracle
export J2SDKDIR=/usr/lib/jvm/java-11-oracle

JDK 8:

export PATH=$PATH:/usr/lib/jvm/java-8-oracle/bin
export JAVA_HOME=/usr/lib/jvm/java-8-oracle
export JRE_HOME=/usr/lib/jvm/java-8-oracle/jre/
export J2SDKDIR=/usr/lib/jvm/java-8-oracle
export J2REDIR=/usr/lib/jvm/java-8-oracle/jre

Load the environments into the current session.

source /etc/profile.d/javajdk.sh

That’s All.

You might also like