How to Install Java 8 on Ubuntu 16.04
Posted on September 12, 2017 • 3 min read • 437 wordsIn 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.
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).
Before we install OpenJDK JRE 8, let’s update our apt metadata database
sudo apt-get update
sudo apt-get install openjdk-8-jre
Press Y to continue the installation process.
To install JDK 8 from OpenJDK we can run command below
sudo apt-get install openjdk-8-jdk
Press Y to continue the installation process
We will install Oracle JDK 8 from webupd8 PPA repository
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
Press Y to continue the installation process.
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)
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!
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!