How to Install JDK 12 on Arch Linux

29/12/2020
Java Development Kit (JDK) is used to compile, run, debug, and sign Java applications. It is used by Java developers all around the world. JDK 12 is the latest release of JDK.

There are 2 versions of JDK. OpenJDK and Oracle JDK. OpenJDK is open source and does not contain any proprietary codes. Oracle JDK is closed source and contains proprietary codes from Oracle.

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

Installing Oracle JDK 12:

Oracle JDK 12 is not available in the official package repository of Arch Linux. But, you can easily download and install Oracle JDK 12 from the official website of Oracle and install it on Arch Linux.

First, visit https://www.oracle.com/technetwork/java/javase/downloads/index.html from your favorite web browser and click on the DOWNLOAD button for Java SE 12.0.1 or Java Platform (JDK) 12.

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

Now, click on the jdk-12.0.1_linux-x64_bin.tar.gz link as marked in the screenshot below.

Your browser should prompt you to save the file. Click on Save File and then click on OK.

Your browser should start downloading Oracle JDK tar.gz archive. It may take a while to complete.

Once the download is complete, navigate to the ~/Downloads directory with the following command:

$ cd ~/Downloads

As you can see, the Oracle JDK 12 tar.gz archive I just downloaded is here.

Now, extract the Oracle JDK 12 tar.gz archive in the /opt directory with the following command:

$ sudo tar xvzf jdk-12.0.1_linux-x64_bin.tar.gz -C /opt

The JDK 12 tar.gz archive should be extracted.

As you can see, a new directory jdk-12.0.1/ is created in the /opt directory. Note the directory name.

Now, you have to create a new environment variable JAVA_HOME and add Oracle JDK 12 binaries to the PATH environment variable. To do that, run the following command:

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

A new file /etc/profile.d/jdk12.sh should be created.

Now, restart your Arch Linux machine with the following command:

$ sudo reboot

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

$ echo $JAVA_HOME && echo $PATH

As you can see, the JAVA_HOME and PATH environment variables are correctly set.

Now, check whether Oracle JDK 12 is working with the following command:

$ java version

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

Installing OpenJDK 12:

OpenJDK 12 is not available in the official package repository of Arch Linux. But, you can download it from the official website of OpenJDK and install it on Arch Linux.

First, visit the official website of OpenJDK 12 at https://jdk.java.net/12/. Once the page loads, click on the tar.gz click as marked in the screenshot below.

Your browser should prompt you to save the OpenJDK 12 tar.gz archive. Select Save File and click on OK.

Your browser should start downloading OpenJDK 12 tar.gz archive. It may take a while to complete.

Once the download is complete, navigate to the ~/Downloads directory with the following command:

$ cd ~/Downloads

As you can see, the OpenJDK 12 tar.gz archive is here.

Now, extract the OpenJDK 12 tar.gz archive in the /opt directory with the following command:

$ sudo tar xvzf openjdk-12.0.1_linux-x64_bin.tar.gz -C /opt

OpenJDK 12 tar.gz archive should be downloaded.

A new directory jdk-12.0.1/ should be created in the /opt directory.

Now, you have to create a new JAVA_HOME environment variable and update the PATH environment variable. To do that, run the following command:

$ echo -e ‘export JAVA_HOME="/opt/jdk-12.0.1"nexport PATH="$PATH:${JAVA_HOME}/bin"n’
| sudo tee /etc/profile.d/openjdk12.sh

A new file /etc/profile.d/openjdk12.sh should be created.

Now, reboot your computer 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 correctly set.

$ echo $JAVA_HOME && echo $PATH

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

$ java version

As you can see, OpenJDK 12 is working correctly.

Compiling a Simple Java Program with JDK 12:

In this section, I will show you how to compile and run a simple Java program with JDK 12.

I have written a simple Java program Welcome.java and saved it in the ~/codes directory.

The contents of the Welcome.java Java source file are as follows:

Now, to compile the Welcome.java source file, run the following command:

$ javac Welcome.java

The Welcome.java Java source file should be compiled and a new file Welcome.class should be generated as you can see in the screenshot below. It’s called a Java class file. The Java source code is converted into Java bytecode and the converted bytecode is saved in the class file, which the JVM (Java Virtual Machine) can run.

Now, you can run the compiled Java class file as follows:

$ java Welcome

NOTE: When you want to run a Java class file, exclude the .class extension.

As you can see, the correct output is displayed.

So, that’s how you install Oracle JDK 12 and OpenJDK 12 on Arch Linux. 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 11 on Ubuntu

The full form of JDK is Java Development Kit. It is used to write and test Java programs. Recently, JDK 11 came out. It...
29/12/2020

Install Latest Oracle Java JDK/JRE 7/8/9 on Linux

Oracle Java is the key foundation for every type of networked application developed. It is the global standard for developing...
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