Install Oracle Java 12 on Ubuntu 18.04/Debian 9.8


This tutorial will guide you on how to install Oracle Java 12 on Ubuntu 18.04/Debian 9.8. To install the official Oracle Java on Ubuntu 18.04 or Debian 9.8, you need to add the PPA repository. But before that, ensure that your system packages are up-to-date.

sudo apt update
sudo apt upgrade

Add Linux Uprising Java PPA Repository

To install Java 12 on Ubuntu 18.04 and Debian 9.8, you need to add the linux uprising java PPA repository as shown below;

On Ubuntu 18.04

sudo apt install software-properties-common
sudo add-apt-repository ppa:linuxuprising/java

On Debian 9.8

echo "deb bionic main" | sudo tee /etc/apt/sources.list.d/linuxuprising-java.list
sudo apt install dirmngr
sudo apt-key adv --keyserver hkp:// --recv-keys 73C3DB2A

Install Java 12 on Ubuntu 18.04/Debian 9.8

Once you have the Linux Uprising repositories to install Java 12, proceed to do the installations.

sudo apt update
sudo apt install oracle-java12-installer

Verify Java Installation

Once the installation is done, run the command below to verify the installed Java version.

java --version
java 12.0.1 2019-04-16
Java(TM) SE Runtime Environment (build 12.0.1+12)
Java HotSpot(TM) 64-Bit Server VM (build 12.0.1+12, mixed mode, sharing)

If you need to set Oracle Java 12 as the default Java version, install the following package if not already installed.

apt install oracle-java12-set-default

Define JAVA_HOME Environment Variable

In order to set Java home environment variable, you first need to Java installation location by running the command below;

sudo update-alternatives --config java
There is 1 choice for the alternative java (providing /usr/bin/java).
Selection Path Priority Status
0 /usr/lib/jvm/java-12-oracle/bin/java 1091 auto mode
1 /usr/lib/jvm/java-12-oracle/bin/java 1091 manual mode
Press to keep the current choice[*], or type selection number:

Now that we got the Java install location, press Ctrl+c and open the /etc/environment configuration file where you can set Java home environment variable as shown below.

vim /etc/environment

Next, source the /etc/environment file to load the environment variables.

source /etc/environment

To confirm the Java home environment variable setting, run the command below;


Well, you are good to go. That is all on how to install Oracle Java 12 on Ubuntu 18.04/Debian 9.8. Enjoy


Please enter your comment!
Please enter your name here