How to Install Java 8 on Ubuntu 16.04

Overview

Java 8 is the current stable Java version since Java 7 is already reach end of life and Java 9 is not released yet.

In this tutorial we’ll learn how-to install Java 8 on Ubuntu 16.04. We will learn how-to install OpenJDK and also Oracle Java.

There are two packages of Java that we can choose. If we need to run Java application, we only need to install Java Runtime Environment (JRE).

Install OpenJDK Java 8

Before we install OpenJDK JRE 8, let’s update our apt metadata database


$ sudo apt-get update

Install OpenJDK JRE 8


$ sudo apt-get install openjdk-8-jre

[][1]

Press Y to continue the installation process.

Install OpenJDK JDK 8

To install JDK 8 from OpenJDK we can run command below


$ sudo apt-get install openjdk-8-jdk

[][2]

Press Y to continue the installation process

Install Oracle JDK 8

We will install Oracle JDK 8 from [webupd8 PPA repository][3].

First of all add webupd8team PPA repository


$ sudo add-apt-repository ppa:webupd8team/java
...
More info: https://launchpad.net/~webupd8team/+archive/ubuntu/java
Press [ENTER] to continue or ctrl-c to cancel adding it

gpg: keyring `/tmp/tmpelw3wxjq/secring.gpg' created
gpg: keyring `/tmp/tmpelw3wxjq/pubring.gpg' created
gpg: requesting key EEA14886 from hkp server keyserver.ubuntu.com
gpg: /tmp/tmpelw3wxjq/trustdb.gpg: trustdb created
gpg: key EEA14886: public key "Launchpad VLC" imported
gpg: no ultimately trusted keys found
gpg: Total number processed: 1
gpg: imported: 1 (RSA: 1)
OK

You will need to press ENTER to finish adding webupd8 repository. I omit some of the output for clarity.

Update apt metadata database.


$ sudo apt-get update

Now let’s install Oracle JDK 8 using command below


$ sudo apt-get install oracle-java8-installer

[Install Oracle Java 8][4]

Press Y to continue the installation process.

[][5]

Press OK to agree with Oracle Binary Code License agreement

Choose Yes To agree with Oracle Binary code license terms.

It might take some time to finish since the installer will also download JDK Package from Oracle website and the size of this package is pretty large.

Oracle JDK 8 installed. Let’s check Java version installed


$ java -version
java version "1.8.0_144"
Java(TM) SE Runtime Environment (build 1.8.0_144-b01)
Java HotSpot(TM) 64-Bit Server VM (build 25.144-b01, mixed mode)

Hello Java From Xenial

Create new file called hellohowtodojo.java with contents below:


class HelloHowtoDojo {
  public static void main(String[] args) {
    System.out.println("Hello HowtoDojo!");
  }
}

```

Compile the source code above using command below

```

$ javac hellohowtodojo.java

```

The process above will create a new file called `hellohowtodojo.class`. Lets run this file

```

$ java HelloHowtoDojo
Hello HowtoDojo!

```

## Summary

In this tutorial we learned how to install OpenJDK Java 8 from Ubuntu repository and also Oracle JDK 8 using webupd8 repository. We also learned how-to create our first java program and compiled it into Java bytecode. Have fun with Java!

 [1]: https://www.howtodojo.com/wp-content/uploads/2017/09/how-to-install-java-8-ubuntu-16.04-01.png
 [2]: https://www.howtodojo.com/wp-content/uploads/2017/09/how-to-install-java-8-ubuntu-16.04-02.png
 [3]: https://launchpad.net/~webupd8team/+archive/ubuntu/java
 [4]: https://www.howtodojo.com/wp-content/uploads/2017/09/how-to-install-java-8-ubuntu-16.04-03.png
 [5]: https://www.howtodojo.com/wp-content/uploads/2017/09/how-to-install-java-8-ubuntu-16.04-04.png