Howtodojo logo
  • Home 
  • About 
  • Certifications 
  • Sample Database 
  • Cheatsheet 
  • Glossary 
  • Blog 
  • Tags 
  1.   Blog
  1. Home
  2. Blog
  3. How to Install Java 8 on Ubuntu 16.04

How to Install Java 8 on Ubuntu 16.04

Share via
Howtodojo
Link copied to clipboard

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.

On this page
Overview   Install OpenJDK Java 8   Install OpenJDK JRE 8   Install OpenJDK JDK 8   Install Oracle JDK 8   Hello Java From Xenial   Summary  
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

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

Press Y to continue the installation process

Install Oracle JDK 8  

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)

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!

 How to Install Go on Ubuntu 16.04
How To Install Git on Ubuntu 16.04 
On this page:
Overview   Install OpenJDK Java 8   Install OpenJDK JRE 8   Install OpenJDK JDK 8   Install Oracle JDK 8   Hello Java From Xenial   Summary  
Follow me

We publish tutorials, tips and tricks about Linux, open source, cloud computing, and infrastructure

     
Copyright © 2012 - 2025 howtodojo.com. |
Howtodojo
Code copied to clipboard