How to Download and Install Oracle JAVA 8 on Ubuntu 18.04/16.04 LTS

In this article, We are going to perform How to Download and Install Oracle JAVA 8 on Ubuntu 18.04/16.04 LTS Manually.


Java is a set of software and specifications developed at Sun Microsystems. There are two tyes of Java Platforms are JDK (Java Development Kit) and JRE (Java Runtime Environment). Both are helpful for deploying applications on servers and debugging, JVM monitoring,developing.

Java 8 Features:

Java 8 provides following features,

  • ForEach() method
  • Functional interfaces
  • Base64 Encode Decode
  • Parallel array sorting
  • Nashorn JavaScript Engine,
  • Parallel Array Sorting
  • Type and Repating Annotations
  • java.lang and java.util Packages

To know more detailed features go through this link.


  • Ubuntu Server 16.04/18.04 LTS
  • SSH access with sudo privileges

To check Ubuntu version:

$ uname -a


$ cat /etc/os-release


$ cat /etc/os-release

VERSION="16.04.5 LTS (Xenial Xerus)"
PRETTY_NAME="Ubuntu 16.04.5 LTS"

Follow the below steps to Install Oracle Java 8 on Ubuntu Manually using command line.

Step 1: Download Oracle Java 8

Generally Oracle will not allow to download directly without accepting their licences. We have to create one account in Oracle java website by your personal or official mail. After accepting licence download the application from browser to local machine.

This link takes you to the Oracle home website Oracel Java SRE.

Once you opened above link goto “JAVA SE Development Kit 8u231” section, click on “Accept License Agreement” Radio button and download “jdk-8u231-linux-x64.tar.gz” setup for ubuntu.

download jdk 1.8

After downloading into local machine, using SCP/SFTP/FTP transfer the file from local machine to Ubuntu server.

Step 2: Copy downloaded Setup and Extract

Create a directory /opt/jdk

$ sudo mkdir  -p /opt/jdk

Copy the tar  file from the directory copied from local machine to server to /opt/jdk folder and execute below command:

$ sudo cp -rf /home/sivasai/jdk-8u231-linux-x64.tar.gz /opt/jdk/
$ cd /opt/jdk/
$ sudo tar -zxf jdk-8u231-linux-x64.tar.gz

Now unarchived the file and check the content by long-list:

# ls

Step 3: Install Oracle Java 8 on ubuntu with Alternatives

Use update-alternatives command to configure java on your system
$ sudo update-alternatives --install /usr/bin/java java /opt/jdk/jdk1.8.0_231/bin/java 100
After executing above command it shows below output:
update-alternatives: using /opt/jdk/jdk1.8.0_231/bin/java to provide /usr/bin/java (java) in auto mode

Note : Its not particularly o/p if you have installed open jdk before

Step 4: Verify Update Alternatives

Enter below command shows output:
$ sudo update-alternatives --display java
java - auto mode
  link best version is /opt/jdk/jdk1.8.0_231/bin/java
  link currently points to /opt/jdk/jdk1.8.0_231/bin/java
  link java is /usr/bin/java
/opt/jdk/jdk1.8.0_231/bin/java - priority 100
/opt/jdk/jdk1.8.0_231/bin/javac - priority 100
To change for alternative mode:
$ sudo update-alternatives --config java
It prompts for selecting by 0,1, choose accordingly:
 There are 2 choices for the alternative java (providing /usr/bin/java).

  Selection    Path                             Priority   Status
* 0            /opt/jdk/jdk1.8.0_211/bin/java    100       auto mode
  1            /opt/jdk/jdk1.8.0_231/bin/java    100       manual mode
  2            /opt/jdk/jdk1.8.0_211/bin/javac   100       manual mode

Press <enter> to keep the current choice[*], or type selection number:

Step 5: Setting the JAVA_HOME and JRE_HOME Environment Variables

To define the enviroment variable:
$ sudo  nano /etc/environment
Paste the below varible on the file:
To check variables defined:
$ source /etc/environment
$ echo $JAVA_HOME
$ sudo apt-get update

Step 6: Verify Java Version

To check the java version:
$ java -version
java version "1.8.0_231"
Java(TM) SE Runtime Environment (build 1.8.0_211-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.211-b12, mixed mode)
If you seeing output like above then we have  successfully set up the Java 8 on Ubuntu.


In this article, We have downloaded Oracle Java 8 from official site, installed using command line, configured JAVA_HOME and JRE_HOME, verified installed version.

Related Articles:

How to Download and Install Oracle Java 8 on CentOS 7 

How to Download and Install Oracle JAVA 11 on Ubuntu 18.04/16.04 LTS

Sivasai Sagar

I am working as DevOps Engineer and having 5 years of Experience. Likes to share knowledge.

10 thoughts on “How to Download and Install Oracle JAVA 8 on Ubuntu 18.04/16.04 LTS”

    • Hello Runkeish,
      Thanks for following our article. Please give read, write,and group permissions to /opt/jdk directory. Then you can move the files.
      $ sudo chmod -R 777 /opt/jdk
      Let me know if you still facing the issue.

  1. sudo update-alternatives –install /usr/bin/javac javac /opt/jdk/jdk1.8.0_231/bin/javac 100

    You might need to add this as we need javac!

  2. I have fallowed above all steps but still i am facing issue.
    while running the “java -version”.It was not showing jdk version.Could you please help me.


Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Share via
Copy link