Install Oracle Java 8 on Ubuntu 18.04

Reading Time: 2 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 16.04 server
  • No installations of previous Java versions

Install Java

Step 1: Updating your system

apt-get update && apt-get upgrade

Step 2: Install the Repo

First, install the repository, its provided by a third party and you’ll need to press enter to continue downloading. The Oracle Java (JDK) Installer automatically downloads and installs Oracle JDK8.

add-apt-repository ppa:webupd8team/java

Update your system once more
apt-get update

Step 3: Install Java 8

Using the command below will kickstart the Java Installer which will assist in our task. Press Y when prompted to continue.

apt-get install oracle-java8-installer

Once you come to the Installer page click OK and Yes to agree to their licensing and terms.

configure oracle java 8 installer


Step 4: 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. Afterward, use the source command to have the system recognize the changes in your file.

source /etc/environment

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

Example Output:
root@1804:~# echo $JAVA_HOME

Author Bio

About the Author: Echo Diaz

Throughout Echo's four year stint as a technical support specialist, her passion for breaking down complex concepts has to lead to a career in professional writing. As a top tier support specialist, she adds a distinctive element to her written work that speaks to customer feedback and concerns.

Echo occasionally pops her head out from behind her computer to watch her dog energetically run around the yard and unabashedly shovels money into buying tickets to see her favorite musical artists.

Refer a friend and get a $50 hosting credit!