How To Setup Java on Ubuntu 16.04

Java is a general-purpose computer programming language which is used from many software applications or websites.

Java is available from the Open Source project OpenJDK and freely available from Oracle.

Some Java applications require Oracle Java. This is my case. Here I describe the available solutions.

Install OpenJDK

Use the following command to install OpenJDK

sudo apt-get install default-jre

Install Oracle Java

You can install Oracle Java

  1. using PPA repository
  2. with direct download

Personally, I prefer the second method.

Using PPA repository

sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update


sudo apt-get install oracle-java8-installer

Direct download

Go to Oracle Downloads at section “Java Platform, Standard Edition” and click the current Java version. Download the JDK from the available options. In this example jdk-8u92-linux-x64.tar.gz (JDK 8u92 for Linux x64).

Move the dowwnloaded file to /opt. Then:

cd /opt
tar xvzf jdk-8u92-linux-x64.tar.gz


sudo nano /etc/environment




source /etc/environment

Test your environment with the following command: