Install Oracle Java 12 on Ubuntu 18.04/Debian 9.8

|
Last Updated:
|
|

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 http://ppa.launchpad.net/linuxuprising/java/ubuntu bionic main" | sudo tee /etc/apt/sources.list.d/linuxuprising-java.list
sudo apt install dirmngr
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --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
JAVA_HOME="/usr/lib/jvm/java-12-oracle"

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;

echo $JAVA_HOME
/usr/lib/jvm/java-12-oracle

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

SUPPORT US VIA A VIRTUAL CUP OF COFFEE

We're passionate about sharing our knowledge and experiences with you through our blog. If you appreciate our efforts, consider buying us a virtual coffee. Your support keeps us motivated and enables us to continually improve, ensuring that we can provide you with the best content possible. Thank you for being a coffee-fueled champion of our work!

Photo of author
koromicha
I am the Co-founder of Kifarunix.com, Linux and the whole FOSS enthusiast, Linux System Admin and a Blue Teamer who loves to share technological tips and hacks with others as a way of sharing knowledge as: "In vain have you acquired knowledge if you have not imparted it to others".

Leave a Comment