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

How to Install JDK 12 on Arch Linux

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

JMap and JStack Tutorial

For any java delopers Jmap and Jstack are two important utility programs that can be used to debug issues, or understand...
28/12/2020

Java 11 New Features

Oracle has recently released Java Development Kit 10 (JDK 10), and that means JDK 11 is not far away, in accordance with...
28/12/2020
Bài Viết

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

Huớng dẫn dùng proxy cho ios, iphone 2023
23/09/2023

Cách gắn set proxy cho điện thoại android, oppo, giả lập android, Ldplayer Bằng Proxydroid
20/09/2023

Mua Proxy Socks5 VN Chơi Game Gia Lập Tăng Cường Trải Nghiệm Chơi Game
22/06/2023

Mua Proxy Mỹ, Us Nuôi Tài Khoản Etsy, eBay Tìm Hiểu Về Mua Proxy Mỹ tại Onet.com.vn
22/06/2023

Mua Proxy Game – Giải pháp tuyệt vời cho việc chơi game trên mạng mà không bị giới hạn về vị trí địa lý
03/06/2023