Install Oracle Java 8 on Ubuntu 18.04

Posted on by David Singer
Reading Time: 3 minutes

Java is a programming language used to build Android apps and real life web applications like Gmail and Google Docs. This ubiquitous language can be installed onto an Ubuntu server and its what we’ll be teaching in this tutorial today.


  • 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 VPS server
  • No installations of previous Java versions

Install Java

Step 1: Updating your system

apt-get update && apt-get upgrade

Step 2: Download Java

Follow these steps to download and install Java for Linux. This procedure installs the Java Runtime Environment (JRE) for 64-bit Linux, using an archive binary file (.tar.gz).

Go to and click on the Download button.

Download and check the downloaded file size to ensure that you have downloaded the full, uncorrupted software bundle. Before you download the file, take notice of the files 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.


The instructions below 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.

A note about root access: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 to the directory in which you want to install. Type:

cd directory_path_name

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

cd /usr/java/

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

Unpack the tarball and install Java

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

The Java files are 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.

Lastly, delete the .tar.gz file if you want to save disk space.

Next, verify the Installation of Java 8.

java -version

Example Output:

java version "1.8.0_201"
 Java(TM) SE Runtime Environment (build 1.8.0_201-b09)
 Java HotSpot(TM) 64-Bit Server VM (build 25.201-b09, mixed mode)

Set Java’s Home Environment

You may be looking to set Java’s home environment once we’ve installed it onto our server. To do that, lets first, let’s find Java’s path.

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

Take the highlighted path and add the variable into your /etc/environment file. Add the JAVA_HOME path after any line that is already present.

vim /etc/environment

Once you are in the file type i to insert the needed line:


Save and exit the file by typing ESC followed by :wq and press enter.

After this, we can use the source command to ensure the system recognizes the changes in our file.

source /etc/environment

You’ll know the variable has been set correctly by calling the variable.


Example Output:

root@host:~# echo $JAVA_HOME

The Most Helpful Humans In Hosting™

Liquid Web prides ourselves as 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 [email protected], by phone (at 800-580-4986) or via a LiveChat for whatever method you prefer. We work hard for you so you don't have to!!!

Avatar for David Singer

About the Author: David Singer

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

Latest Articles

Using a Cloudflare Argo Tunnel with load balancing

Read Article

Subdomain takeover — protect your website against it!

Read Article

Controlling PHP settings with a custom php.ini file

Read Article

Linux dos2unix command syntax — removing hidden Windows characters from files

Read Article

Change cPanel password from WebHost Manager (WHM)

Read Article