How to Install Oracle Java on Ubuntu 18.04

Java is one of the most popular programming language for system software development and web application in the world.

If you only want to run Java programs then you need JRE which contains only the Java Runtime Environment and if you are Java developer then you will need JDK which also includes the development/debugging tools and libraries.

In this article,we will show you how to install Oracle Java on Ubuntu 18.04.

Prerequisites

Installing Oracle Java On Ubuntu

In the following sections ,we will explain two ways to install Oracle Java.

  • 1、Install Oracle Java using Official Source.
  • 2、Install Oracle Java using PPA.

Install Oracle Java using Official Source.

You can visit the Oracle JDK page to download.Before installing Oracle Java make sure you read the Oracle JDK License. The license permits only non-commercial use of the software, such as personal use and development use.

In the following introduction,wo will use Oracle Java JDK 11 (LTS) as an example.

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

After the download is complete, use the tar command to extract the downloaded archive to the specified directory (Ex:/opt/).

tar -zxvf jdk-*
sudo mv jdk* /opt/

After completing the above command operation,You need to use the following command to install Oracle java.

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

Replace *with Java specific version information.If you have multiple versions of java installed on your system,you need to use the following command to set the default java using the below command.

sudo update-alternatives --config java

The output will look something like this:

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

Then choose the 1 (Number below the selection column) and press Enter.

To verify the current version of java,Type follow command:

java -version

The output will look something like this:

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)

Install Oracle Java using PPA

Oracle Java 11 can be installed from the Linux Uprising PPA.The following describe how to install Oracle Java 11 on Ubuntu 18.04:

Add the Oracle Java PPA to your Ubuntu system.This PPA contains a package oracle-java11-installer having the Java installation script.

sudo add-apt-repository ppa:linuxuprising/java

Update the packages list and install the oracle-java-11 packages by following command:

sudo apt update
sudo apt install oracle-java11-installer

Verify the installation by running the following command which will print the Java version:

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)

To verify the current version of java,Type follow command:

java -version

The output will look something like this:

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)

Set JAVA Environmental Variables

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

Edit the .profile file in the current user root director:

vim .profile

Add the following lines, at the end of the file:

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

Conclusion

That`s All.In this article,you learned how to install oracle java on Ubuntu 18.04.If you have any questions or thoughts to share, don’t forget to leave a comment to reach us.

Leave a Reply