How To Install Oracle Java 8 in Ubuntu 16.04

Reading Time: 3 minutes

Oracle’s Java 8 is a programming language that creates many of the applications and websites in use today.  Its ubiquitous and stable nature makes it a favorite amongst Google and Android developers for the last 20 years. If you have a Liquid Web Core Managed Ubuntu LTS VPS server, contact our support team for help with installation.  Otherwise, this tutorial guides you through how to install Java 8 (Java Development Kit) and set the path of the JAVA_HOME variable.

PreFlight Check

  • Open the terminal and log in as root.  If you are logged in as another user, you will need to add sudo before each command.
  • Working on a Linux Ubuntu 16.04 server
  • No installations of previous Java versions

Install Oracle Java 8

Step 1:  Update & Upgrade

It is advised to update your system by copy and pasting the command below.  Be sure to accept the update by typing Y when asked to continue:

apt-get update && apt-get upgrade

Step 2: Install Java 8

Download

This procedure uses a tar.gz install of the Java Runtime Environment (JRE) for 64-bit Linux, using an archive binary file.

  1. Go to http://java.com and click on the Download button.
  2. Download and check the download file size to ensure that you have downloaded the full, uncorrupted software bundle. Before you download the file, note its byte size provided on the download page on the website. Once the download has completed, compare that file size to the size of the downloaded file to make sure they are equal.

Install

These instructions are for installing version Java 8 Update 73 (8u73). If you are installing another version, make sure you change the version number appropriately when you type the commands at the terminal. 

Example: For Java 8u79 replace 8u73 with 8u79. Note that, as in the preceding example, the version number is sometimes preceded with the letter u, and sometimes it is preceded with an underbar, for example, jre1.8.0_73.

Note:
To install Java in a system-wide location such as /usr/local, you must login as the root user to gain the necessary permissions. If you do not have root access, install Java in your home directory or a subdirectory for which you have write permissions.

Change directories

Now, cd into the directory in which you want to install Java. Type in:

cd directory_path_name

For example, to install the software in the /usr/java/ directory, Type:

cd /usr/java/

Unpack the Tarball and Install Java

Next, we want to move the downloaded .tar.gz archive binary to the current directory.

tar zxvf jre-8u73-linux-x64.tar.gz

The Java files will be installed in a directory called jre1.8.0_73 in the current directory. In this example, it is installed in the /usr/java/jre1.8.0_73 directory. When the installation has completed, you will see the word Done.

Remove File

Finally, Delete the .tar.gz file if you want to save disk space.

Verify Java 8 is Installed

java -version

Output:

java version "1.8.0_181"
Java(TM) SE Runtime Environment (build 1.8.0_181-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.181-b13, mixed mode)

Set Java’s Home Environment

It’s essential to know the path of our Java installation for our applications to function. Where is Java installed? Run this command to find its path:

update-alternatives --config java

Output:

~# update-alternatives --config java
There is 1 choice for the alternative java (providing /usr/bin/java).
Selection Path Priority Status
------------------------------------------------------------
0 /usr/lib/jvm/java-8-oracle/jre/bin/java 1081 auto mode
* 1 /usr/lib/jvm/java-8-oracle/jre/bin/java 1081 manual mode

Next, copy the highlighted path from the second row:
/usr/lib/jvm/java-8-oracle/jre/bin/java/ 
After copying, open the file
/etc/environment
and add in the path of your Java installation to the end of your file.

vim /etc/environment
JAVA_HOME="/usr/lib/jvm/java-8-oracle/jre/bin/java"

Then, save the file by hitting the ESC button and typing :wq to exit vim.

Next, execute the command below to recognize the changes to the file:

source /etc/environment

You should now see the path of installation when using the $Java_Home variable:

echo $JAVA_HOME

Output:

~# echo $JAVA_HOME
/usr/lib/jvm/java-8-oracle/jre/bin/java

The Most Helpful Humans In Hosting™

We pride ourselves on being The Most Helpful Humans In Hosting™! Our support staff is always available to assist with any Dedicated, Cloud, or VPS server issues 24 hours a day, 7 days a week 365 days a year.

We are available, via our ticketing systems at support@liquidweb.com, by phone (at 800-580-4986) or via a LiveChat for whatever method you prefer. We work hard for you so you can relax.

Author Bio

About the Author: David Singer

I am a g33k, Linux blogger, developer, student and Tech Writer for Liquidweb.com/kb. My passion for all things tech drives my hunt for all the coolz. I often need a vacation after I get back from vacation....

Refer a friend and get a $50 hosting credit!