How To Install Oracle Java 12 / 11 / 8 on Ubuntu 18.04 & Linux Mint 19

0

Today we will be going through the steps to install Oracle Java JDK on Ubuntu 18.04 & Linux Mint 19. Java JDK is the base for the JAVA developers, and this guide will be more useful for them to build a development environment when they especially use Ubuntu or Linux Mint.

Prerequisites

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

Install Oracle Java JDK 10 / 11 / 8

We can install Oracle Java JDK in two ways,

1: Install Oracle Java JDK using Official Source

2: Install Oracle Java JDK using PPA

1: Install Oracle Java JDK Using Official Source

Download Oracle Java

You can either use command line or browser to download the JDK, better to use the browser, the easiest one.

Visit the Oracle JDK page to download.

Oracle Java JDK 11 (LTS):

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

Oracle Java JDK 12:

Download Oracle JDK 12 (v12.0.1)

Oracle Java JDK 8:

Download Oracle JDK 8 (v8u211) (Login Required)

If you still want to use the command line, use the below command.

### Oracle Java JDK 11 ###

LOGIN REQUIRED

### Oracle Java JDK 12 ###

wget --no-check-certificate --no-cookies --header "Cookie: oraclelicense=accept-securebackup-cookie" https://download.oracle.com/otn-pub/java/jdk/12.0.1+12/69cfe15208a647278a19ef0990eea691/jdk-12.0.1_linux-x64_bin.tar.gz

### Oracle Java JDK 8 ###

LOGIN REQUIRED

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

tar -zxvf jdk-*

sudo mv jdk* /usr/

Install Oracle Java

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

### Oracle Java 12 ###

sudo update-alternatives --install /usr/bin/java java /usr/jdk-12.*/bin/java 1

### Oracle Java 11 ###

sudo update-alternatives --install /usr/bin/java java /usr/jdk-11.*/bin/java 2

### Oracle Java 8 ###

sudo update-alternatives --install /usr/bin/java java /usr/jdk1.8.*/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.

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-11.0.3/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-11.0.3/bin/java to provide /usr/bin/java (java) in manual mode

If you require Oracle Java 11, then choose the 1 (Number below the selection column) and press Enter.

2: Install Oracle Java JDK Using PPA

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

### Oracle Java 12 / 11 ### 

sudo add-apt-repository ppa:linuxuprising/java

### Oracle Java 8 ###

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

Now, install Java JDK using the apt command.

### Oracle Java 12 ###

sudo apt install -y oracle-java12-installer

### Oracle Java 11 ### 

sudo apt install -y oracle-java11-installer

### Oracle Java 8 ###

sudo apt install -y oracle-java8-installer

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

Set Default Java Version

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

### Oracle Java 12 ###

sudo apt install -y oracle-java12-set-default

### Oracle Java  11 ###

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

### Oracle Java 8 ###

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

Verify Java

Now, check the java version using the following command.

java -version

Output:

Oracle Java 11:

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

The output will vary depending upon the version of Oracle Java installed on your system.

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 variables based on the JDK location and version.

The location of Java mentioned in the variables are from the Java installed using the official source.

Oracle Java 12:

export PATH=$PATH:/usr/jdk-12.0.1/bin
export JAVA_HOME=/usr/jdk-12.0.1
export J2SDKDIR=/usr/jdk-12.0.1

Oracle Java 11:

export PATH=$PATH:/usr/jdk-11.0.3/bin
export JAVA_HOME=/usr/jdk-11.0.3
export J2SDKDIR=/usr/jdk-11.0.3

Oracle Java 8:

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

To load the environments into the current session, run:

source /etc/profile.d/javajdk.sh

Conclusion

That’s All. Hope this post helped you install Oracle Java on your Ubuntu 18.04 / Linux Mint 19 system. Java is a must to run applications such as Tomcat, Gradle, ELK Stack, Graylog, Eclipse IDE, etc.

You might also like