How-to Install JDK 8 On Ubuntu 15.04


Java comes with two different version, JDK or Java Development Kit where you can develop Java app using these compilation of tools. Another version is JRE or Java Runtime Environment, if you only need to run Java application, you can use this. In this tutorial we’ll learn how to install Java Development Kit version 8 on Ubuntu 15.04.

Install Java Development Kit (JDK) 8

We will install JDK 8 from [Webupd8 PPA][1].

First let’s add webupd8 team PPA repository.

$ sudo add-apt-repository ppa:webupd8team/java
Press [ENTER] to continue or ctrl-c to cancel adding it


You need to press enter to continue adding the webupd8team PPA repository. I truncate the output above to show you only the most important part.

Next, we’ll update local metadata to include webupd8 repository.

$ sudo apt-get update

Now, we can install Oracle JDK 8.

$ sudo apt-get -y install oracle-java8-installer

Package configuration. Choose OK

[accept oracle java license][2]

Accepting Oracle Binary Code License Terms. Choose Yes

[Oracle Binary Code License Terms][3]

After installing Java 8, you can check the current java version by running command below :

$ java -version
java version "1.8.0_45"
Java(TM) SE Runtime Environment (build 1.8.0_45-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.45-b02, mixed mode)

We confirmed that we already have JDK 8 installed.

Setting Up JAVA_HOME

Let’s check first where java installed

sudo update-alternatives --config java
There is only one alternative in link group java (providing /usr/bin/java): /usr/lib/jvm/java-8-oracle/jre/bin/java
Nothing to configure.

from the output above we can see that the JAVA_HOME that we need is /usr/lib/jvm/java-8-oracle/jre/

On /etc/environment, add JAVA_HOME on the last line :


Trying Java

Create a new file with name with contents below :

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


From terminal, run :


$ javac


If no error, javac should produce `HelloWorld.class`. To run this file you can use java


$ java HelloWorld


## Summary

We learned how to install JDK 8 on Ubuntu 15.04, setting up `JAVA_HOME` environment variable that usually needed by Java based application. We also learned how to compile simple Java app and run it.