How To Install Oracle Java JDK 10 / 8 on Ubuntu 18.04 / Ubuntu 17.10


Today we will be going through the steps to install Oracle Java JDK 10 / 8 on Ubuntu 18.04 / Ubuntu 17.10. Java SDK is the base for the JAVA developers, and this guide will be more useful for them to build development environment when they especially use Ubuntu.

Open up a terminal and switch to the root user.

sudo su -


su -

Method 1: Install Oracle Java JDK 10 / 8 on Ubuntu 18.04 using Official Source

You can download the Oracle JDK either using command line or browser. Recommend you to use the browser to download the Oracle JDK.

Download using browser

Oracle Java JDK 10: (Current)

Download Oracle JDK 10

Oracle Java JDK 8: (End of Public Updates)

Download Oracle JDK 8

Oracle Java JDK 9: (End of Life)

Download Oracle JDK 9

Download using terminal

### Oracle Java JDK 10 ###

wget --no-check-certificate --no-cookies --header "Cookie: oraclelicense=accept-securebackup-cookie"

### Oracle Java JDK 8 ###

wget --no-check-certificate --no-cookies --header "Cookie: oraclelicense=accept-securebackup-cookie"

Extract the downloaded JDK archive using the tar command to the desired directory (Ex. /usr/)

tar -zxvf jdk-*

mv jdk* /usr/

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

update-alternatives --install /usr/bin/java java /usr/jdk*/bin/java 2

update-alternatives --config java

The above command would list all Java JDK installed on your system, 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/jdk-10.0.1/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/jdk-10.0.1/bin/java to provide /usr/bin/java (java) in manual mode

If you require Oracle Java JDK 10, then choose the 1 and press enter.

Method 2: Install Oracle Java JDK 10 / 8 on Ubuntu 18.04 using PPA

Add the JAVA JDK PPA using the add-apt-repository comamnd.

### Oracle JDK 10 ###

sudo add-apt-repository ppa:linuxuprising/java

### Oracle JDK 8 ###

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

Now, install Java JDK using the apt-get command.

### Oracle JDK 10 ###

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

### Oracle JDK 8 ###

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

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

Verify the Java

Now, check the java version using the following command.

java -version


Oracle Java JDK 10:

java version "10.0.1" 2018-04-17
Java(TM) SE Runtime Environment 18.3 (build 10.0.1+10)
Java HotSpot(TM) 64-Bit Server VM 18.3 (build 10.0.1+10, mixed mode)

Oracle Java JDK 8:

java version "1.8.0_171"
Java(TM) SE Runtime Environment (build 1.8.0_171-b11)
Java HotSpot(TM) 64-Bit Server VM (build 25.171-b11, mixed mode)

Setup JAVA Environmental Variable

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

Set the environmental variables like below using the export command.

export JAVA_HOME=/usr/jdk-10.0.1

export JRE_HOME=/usr/jdk-10.0.1/jre/

Set PATH variable too.

export PATH=$JAVA_HOME/bin:$PATH

To set these variables permanent, place the above commands in the /etc/profile (For all users) or ~/.bash_profile (For single user) file.

That’s All. You have successfully installed Oracle Java JDK on Ubuntu 18.04.

Further Reading

You might also like