How to Install JDK 12 on Ubuntu 19.04

29/12/2020
Java Development Kit or JDK in short is a tool for developing Java apps. You can compile your Java codes, run it, test it, sign it and many more with JDK.  There are 2 versions of JDK. One is called OpenJDK and the other one is called Oracle JDK.  OpenJDK is a project to keep JDK free of proprietary codes from Oracle. It’s an open source implementation of Oracle JDK. Oracle JDK contains proprietary codes from Oracle. So, it’s not open source and has many restrictions.

In this article, I am going to show you how to install Open JDK 12 and Oracle JDK 12 on Ubuntu 19.04. So, let’s get started.

Installing OpenJDK 12:

OpenJDK 12 is available in the official package repository of Ubuntu 19.04. So, you can easily install it with the APT package manager.

First, update the APT package repository cache with the following command:

$ sudo apt update

OpenJDK 12 has two versions. A full version and a headless server version.

The headless server version doesn’t have any GUI programming libraries included. The headless version also requires less disk space.

If you want to install the full version of OpenJDK 12, then run the following command:

$ sudo apt install openjdk-12-jdk

If you want to install the headless server version of OpenJDK 12, then run the following command:

$ sudo apt install openjdk-12-jdk-headless

Now, press y and then press <Enter> to continue.

OpenJDK 12 should be installed.

Now, run the following command to check whether OpenJDK is working correctly.

$ java -version

OpenJDK is working correctly.

Installing Oracle JDK 12 using PPA:

You can also install Oracle JDK 12 on Ubuntu 19.04. This version of JDK is not available in the official package repository of Ubuntu. But, you can use linuxuprising/java PPA to install Oracle JDK 12.

To add the linuxuprising/java PPA on Ubuntu 19.04, run the following command:

$ sudo add-apt-repository ppa:linuxuprising/java

Now, press <Enter> to continue.

The PPA should be added.

Now, install Oracle JDK 12 with the following command:

$ sudo apt install oracle-java12-installer

Now, press y and then press <Enter>.

Now, press <Enter>.

Now, select <Yes> and press <Enter> to confirm the Oracle Technology Network License Agreement for Oracle Java SE.

Oracle JDK 12 is being installed.

Oracle JDK 12 should be installed.

Once Oracle JDK 12 is installed, run the following command to check whether it is working or not.

$ java -version

As you can see, Oracle JDK 12 is working correctly.

Installing Oracle JDK 12 from the Official Website:

You can also install Oracle JDK from the official website.

First, visit https://www.oracle.com/technetwork/java/javase/downloads/index.html from any web browser. Once the page loads, click on the Download button of Java Platform (JDK) 12 as marked in the screenshot below.

Now, click on Accept License Agreement to accept the Oracle Technology License Agreement for Oracle Java SE.

Now, click on the jdk-12.0.1 DEB package file.

NOTE: At the time of this writing, the version is 12.0.1. It might be different by the time you read this article. So, make sure to replace 12.0.1 with the version you are installing from now on.

Your browser should prompt you to download the DEB package file. Select Save File and click on OK.

jdk-12.0.1 is being downloaded.

Now, navigate to the ~/Downloads directory as follows:

$ cd ~/Downloads

The jdk-12.0.1 DEB package file should be here.

Now, install the DEB package file as follows:

$ sudo dpkg -i jdk-12.0.1_linux-x64_bin.deb

jdk-12.0.1 package should be installed.

Now, find the path of the bin/ directory of the deb package jdk-12.0.1 with the following command:

$ dpkg –listfiles jdk-12.0.1 | grep -E ‘.*/bin$’

Now, add the JAVA_HOME and update the PATH variable with the following command:

$ echo -e ‘export JAVA_HOME="/usr/lib/jvm/jdk-12.0.1"nexport PATH="$PATH:${JAVA_HOME}/bin"’
| sudo tee /etc/profile.d/jdk12.sh

Now, reboot your Ubuntu machine with the following command:

$ sudo reboot

Once your computer boots, run the following command to check whether the environment variables JAVA_HOME and PATH are set correctly.

$ echo $JAVA_HOME &amp;&amp; echo $PATH

Now, check whether Oracle JDK 12 is working correctly as follows:

$ java version

Compiling and Running a Simple Java Program:

Now, I am going to write a simple java program to test whether we can compile and run it with OpenJDK  12 and Oracle JDK 12.

Now, create a file Welcome.java and type in the following lines in it.

public class Welcome {
public static void main(String[] args) {
System.out.println("Welcome to LinuxHint!");
}
}

Now, to compile Welcome.java source file, open a Terminal and navigate to the directory where your Welcome.java source file is saved and run the following command:

$ javac Welcome.java

A new file Welcome.class should be generated as you can see in the screenshot below. It is called a Java class file. Java class file contains Java bytecodes that the JVM (Java Virtual Machine) can run.

Now, run Welcome.class Java class file as follows:

$ java Welcome

NOTE: Type in only the filename without .class extension. Otherwise, it won’t work.

Welcome to LinuxHint! Just the output I expected. So, the Welcome.java program compiled and ran successfully using JDK 12.

So, that’s how you install Oracle JDK 12 and OpenJDK 12 on Ubuntu 19.04 LTS. Thanks for reading this article.

ONET IDC thành lập vào năm 2012, là công ty chuyên nghiệp tại Việt Nam trong lĩnh vực cung cấp dịch vụ Hosting, VPS, máy chủ vật lý, dịch vụ Firewall Anti DDoS, SSL… Với 10 năm xây dựng và phát triển, ứng dụng nhiều công nghệ hiện đại, ONET IDC đã giúp hàng ngàn khách hàng tin tưởng lựa chọn, mang lại sự ổn định tuyệt đối cho website của khách hàng để thúc đẩy việc kinh doanh đạt được hiệu quả và thành công.
Bài viết liên quan

Install OpenJDK 9 on Ubuntu

Java is a high level programming language. It is a compiled programming language. But it doesn’t compile Java code to...
28/12/2020

Tess4J Tutorial with Maven And Java

In today’s era when the data is ever growing, the people who deal with data everyday work mostly with unstructured textual...
29/12/2020

Install OpenJDK 10 on Debian 9 Stretch

In short, Java Development Kit (JDK) is used to compile Java source code into Java byte code. Then Java Runtime Environment...
28/12/2020
Bài Viết

Bài Viết Mới Cập Nhật

SỰ KHÁC BIỆT GIỮA RESIDENTIAL PROXY VÀ PROXY DATACENTER
17/02/2024

Mua Proxy v6 US Private chạy PRE, Face, Insta, Gmail
07/01/2024

Mua shadowsocks và hướng dẫn sữ dụng trên window
05/01/2024

Tại sao Proxy Socks lại được ưa chuộng hơn Proxy HTTP?
04/01/2024

Mua thuê proxy v4 nuôi zalo chất lượng cao, kinh nghiệm tránh quét tài khoản zalo
02/01/2024