---
title: "Install Oracle Java 8 on Ubuntu 18.04"
source: "https://docs.nexcess.com/hosting/server-administration/linux/install-oracle-java-ubuntu-18-04/"
description: "Installing Oracle's Java 8 on an Ubuntu 18.04 server has never been easy. Our tutorial teaches you how to install this program in a few steps and we'll also set…"
vertical: "Hosting"
date: "2020-06-05"
last_modified: "2026-07-29"
---

# Install Oracle Java 8 on Ubuntu 18.04

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.

[Explore Ubuntu VPS hosting](https://www.liquidweb.com/vps-hosting/ubuntu-vps/)

## Preflight

- 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](https://www.liquidweb.com/vps-hosting/)
- 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 http://java.com and click on the [**Download**](https://java.com/en/download/linux_manual.jsp) 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.

### Install

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:

```
JAVA_HOME="/usr/lib/jvm/java-8-oracle/jre/bin/java"
```

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.

```
echo $JAVA_HOME
```

**Example Output**:

```
root@host:~# echo $JAVA_HOME
 /usr/lib/jvm/java-8-oracle/jre/bin/java
```
