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

5

ADVERTISEMENT

Oracle SE is popular Java development Kit used to develop Java applications. Here, we will see how to install Oracle Java JDK 11 / 8 on Ubuntu 16.04 & Linux Mint 18.

Prerequisites

To be able to install Oracle Java JDK, you need to log in as a user with sudo privileges.

Install Oracle Java JDK

Visit the Oracle JDK page to download the JDK.

Oracle Java JDK 11 (LTS):

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

Oracle Java JDK 8:

Download Oracle JDK 8 (v8u221) (Login Required)

We would need to extract the downloaded JDK archive to some location. Here, I chose to place JDK in /usr/lib/jvm/ directory.

sudo mkdir /usr/lib/jvm/

Extract the downloaded JDK archive using the tar command.

### Oracle JDK 11 ###

sudo tar -zxvf jdk-11.0.4_linux-x64_bin.tar.gz -C /usr/lib/jvm/

### Oracle JDK 8 ###

sudo tar -zxvf jdk-8u221-linux-x64.tar.gz -C /usr/lib/jvm/

Run update-alternatives command to install the Java on your system.

### Oracle Java 11 ###

sudo update-alternatives --install /usr/bin/java java /usr/lib/jvm/jdk-11.0.4/bin/java 2

### Oracle Java 8 ###

sudo update-alternatives --install /usr/bin/java java /usr/lib/jvm/jdk1.8.0_221/bin/java 3

Set Default Java Version

Set the default java using the below command.

sudo update-alternatives --config java

The above command would list all Java JDK installed on your system, like below.

Choose the default Java version by entering the number below Selection column and press enter.

There are 3 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/lib/jvm/java-8-openjdk-amd64/jre/bin/java   1081      manual mode
  2            /usr/lib/jvm/jdk-11.0.4/bin/java                 2         manual mode
  3            /usr/lib/jvm/jdk1.8.0_221/bin/java               3         manual mode

Press  to keep the current choice[*], or type selection number: 2
update-alternatives: using /usr/lib/jvm/jdk-11.0.4/bin/java to provide /usr/bin/java (java) in manual mode

Here, I chose to have Oracle JDK 11 as the default Java version on my system.

Verify Java

Verify the Java version using the below command.

ADVERTISEMENT

java -version

Output:

java version "11.0.4" 2019-07-16 LTS
Java(TM) SE Runtime Environment 18.9 (build 11.0.4+10-LTS)
Java HotSpot(TM) 64-Bit Server VM 18.9 (build 11.0.4+10-LTS, mixed mode)

The output varies on the version of Java installed on the system.

Setup 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/jdk-11.0.4/bin
export JAVA_HOME=/usr/lib/jvm/jdk-11.0.4/
export J2SDKDIR=/usr/lib/jvm/jdk-11.0.4/

JDK 8:

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

Load the environments into the current session.

source /etc/profile.d/javajdk.sh

Conclusion

That’s All. I hope you have learned how to install Oracle Java JDK 11 / 8 on Ubuntu 16.04 & Linux Mint 18. Please share your feedback in the comments section.

You might also like