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

Twitter4J Tutorial

In this lesson, we’ll use Twitter4J library to mine data from Twitter. Twitter deals with Big Data everyday, but what...
28/12/2020

Install Oracle JDK 10 on Ubuntu 18.04 LTS

How to Install Oracle JDK 10 on Ubuntu 18.04 Oracle JDK is used by Java developers to develop and test Java programs. It...
28/12/2020

How to Install JDK 12 on CentOS 7

Java Development Kit (JDK) is used to develop and test Java applications. It is used by millions of Java developers around...
29/12/2020
Bài Viết

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

Tìm Hiểu Về Thuê Proxy US – Lợi Ích và Cách Sử Dụng Hiệu Quả
11/12/2024

Mua Proxy V6 Nuôi Facebook Spam Hiệu Quả Tại Onetcomvn
03/06/2024

Hướng dẫn cách sử dụng ProxyDroid để duyệt web ẩn danh
03/06/2024

Mua proxy Onet uy tín tại Onet.com.vn
03/06/2024

Thuê mua IPv4 giá rẻ, tốc độ nhanh, uy tín #1
28/05/2024