December 3, 2021
How to install Java 16

How To Install Java 16 (OpenJDK 16 and Oracle Java 16) On Rocky Linux 8

On this tutorial we will learn how to install OpenJDK 16 and Oracle Java 16 on Rocky Linux 8 operating system.

Introduction

Java is one of the most cross-platform, object-oriented, and multipurpose programming language which is mainly used on this age. By using Java, we can create mobile, web, and cloud applications and also we can use Java to create games, chatbots or enterprise applications, and many more. At the time of writing this article, the latest version of Java is Java 16. On this article we will learn how to install Java 16 (including OpenJDK 16 and Oracle Java 16) on Rocky Linux 8 operating system.

Before we start, we are often faced with two Java terminology, namely: OpenJDK and Oracle Java. Don’t be confused, because there are indeed two Java implementations, namely: OpenJDK and Oracle Java. There are almost no differences between them, except Oracle Java has a few additional commercial features.

1. Installing Oracle Java 16 On Rocky Linux 8

1.1 Download Oracle Java 16 source

On this section we will learn how to install Oracle Java 16 on Rocky Linux 8. We will use the Java 16 package from Oracle Website. For this pupose, we will download by using wget command line.

ramansah@otodiginet ~]$ wget --no-check-certificate -c --header "Cookie: oraclelicense=accept-securebackup-cookie" https://download.oracle.com/otn-pub/java/jdk/16.0.2%2B7/d4a915d82b4c4fbb9bde534da945d746/jdk-16.0.2_linux-x64_bin.rpm
--2021-08-14 08:47:01--  https://download.oracle.com/otn-pub/java/jdk/16.0.2%2B7/d4a915d82b4c4fbb9bde534da945d746/jdk-16.0.2_linux-x64_bin.rpm
Resolving download.oracle.com (download.oracle.com)... 23.219.191.139
Connecting to download.oracle.com (download.oracle.com)|23.219.191.139|:443... connected.
HTTP request sent, awaiting response... 302 Moved Temporarily
Location: https://edelivery.oracle.com/otn-pub/java/jdk/16.0.2%2B7/d4a915d82b4c4fbb9bde534da945d746/jdk-16.0.2_linux-x64_bin.rpm [following]
--2021-08-14 08:47:01--  https://edelivery.oracle.com/otn-pub/java/jdk/16.0.2%2B7/d4a915d82b4c4fbb9bde534da945d746/jdk-16.0.2_linux-x64_bin.rpm
Resolving edelivery.oracle.com (edelivery.oracle.com)... 23.219.189.207, 2600:1417:6000:2ba::366, 2600:1417:6000:2ae::366
Connecting to edelivery.oracle.com (edelivery.oracle.com)|23.219.189.207|:443... connected.
HTTP request sent, awaiting response... 302 Moved Temporarily
Location: https://download.oracle.com/otn-pub/java/jdk/16.0.2+7/d4a915d82b4c4fbb9bde534da945d746/jdk-16.0.2_linux-x64_bin.rpm?AuthParam=1628905742_e8779a29bb48ff83685cedb4da5b4f98 [following]
--2021-08-14 08:47:02--  https://download.oracle.com/otn-pub/java/jdk/16.0.2+7/d4a915d82b4c4fbb9bde534da945d746/jdk-16.0.2_linux-x64_bin.rpm?AuthParam=1628905742_e8779a29bb48ff83685cedb4da5b4f98
Connecting to download.oracle.com (download.oracle.com)|23.219.191.139|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 160437916 (153M) [application/x-redhat-package-manager]
Saving to: ‘jdk-16.0.2_linux-x64_bin.rpm’

jdk-16.0.2_linux-x64_bin.rpm     100%[=======================================================>] 153.00M  2.66MB/s    in 58s     

2021-08-14 08:48:01 (2.64 MB/s) - ‘jdk-16.0.2_linux-x64_bin.rpm’ saved [160437916/160437916]
 
Download oracle Java 16
Download Oracle Java 16

The file will be downloaded to home directory. Then we extract them by using command line : sudo rpm -ivh jdk-16.0.2_linux-x64_bin.rpm.

1.2 Install Oracle Java 16

On this stage by using rpm command line, we will extract the Oracle Java 16 package.

[ramansah@otodiginet ~]$ sudo rpm -ivh jdk-16.0.2_linux-x64_bin.rpm
[sudo] password for ramansah: 
warning: jdk-16.0.2_linux-x64_bin.rpm: Header V3 RSA/SHA256 Signature, key ID ec551f03: NOKEY
Verifying...                               ################################# [100%]
Preparing...                              ################################# [100%]
Updating / installing...
   1:jdk-16.0.2-2000:16.0.2-ga        ################################# [100%]
[ramansah@otodiginet ~]$ sudo alternatives --config java

1.3 Verify Oracle Java 16 Version

On my environment, it has been installed OpenJDK 8 and OpenJDK 11. So we will switch the Java alternative to the new ones by submitting command line : sudo alternatives --config java, as shown below :

[ramansah@otodiginet ~]$ sudo alternatives --config java

There are 3 programs which provide 'java'.

  Selection    Command
-----------------------------------------------
   1           java-1.8.0-openjdk.x86_64 (/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.302.b08-0.el8_4.x86_64/jre/bin/java)
 + 2           java-11-openjdk.x86_64 (/usr/lib/jvm/java-11-openjdk-11.0.12.0.7-0.el8_4.x86_64/bin/java)
*  3           /usr/java/jdk-16.0.2/bin/java

Enter to keep the current selection[+], or type selection number: 3
[ramansah@otodiginet ~]$ java -version
java version "16.0.2" 2021-07-20
Java(TM) SE Runtime Environment (build 16.0.2+7-67)
Java HotSpot(TM) 64-Bit Server VM (build 16.0.2+7-67, mixed mode, sharing)
Chosing Oracle Java 16
Chosing Oracle Java 16

2. Installing OpenJDK 16 on Rocky Linux 8

2.1 Download OpenJDK 16

The next is installing OpenJDK 16 on Rocky Linux 8. Adding OpenJDK 16 to the system is simple enough as previous way. The installation is starting by downloading openJDK package using wget command line.

[ramansah@otodiginet ~]$ curl -O https://download.java.net/java/GA/jdk16.0.2/d4a915d82b4c4fbb9bde534da945d746/7/GPL/openjdk-16.0.2_linux-x64_bin.tar.gz
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  175M  100  175M    0     0  2219k      0  0:01:21  0:01:21 --:--:-- 2537k

2.2 Extract OpenJDK 16 Package

After downloading was completed done, then we extract it and move to /opt directory.

[ramansah@otodiginet ~]$ sudo tar xvf openjdk-16.0.2_linux-x64_bin.tar.gz
[sudo] password for ramansah: 
jdk-16.0.2/bin/jar
jdk-16.0.2/bin/jarsigner
jdk-16.0.2/bin/java
jdk-16.0.2/bin/javac
jdk-16.0.2/bin/javadoc
...
[ramansah@otodiginet ~]$ sudo mv jdk-16.0.2 /opt/
ramansah@otodiginet ~]$ vi ~/.bashrc
[ramansah@otodiginet ~]$ source ~/.bashrc
Extract OpenJDK 16
Extract OpenJDK 16
~/.bashrc Filie
~/.bashrc Filie

2.3 Verify OpenJDK 16 installation

We will verify the OpenJDK 16 installation by querying its version. Befor it is done, we have to switch Java alternative to the new ones by executing command line : sudo alternatves –config java, then chose the Java version that we want.

[ramansah@otodiginet ~]$ sudo alternatives --config java

There are 4 programs which provide 'java'.

  Selection    Command
-----------------------------------------------
   1           java-1.8.0-openjdk.x86_64 (/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.302.b08-0.el8_4.x86_64/jre/bin/java)
   2           java-11-openjdk.x86_64 (/usr/lib/jvm/java-11-openjdk-11.0.12.0.7-0.el8_4.x86_64/bin/java)
*+ 3           /usr/java/jdk-16.0.2/bin/java
   4           /opt/jdk-16.0.2/bin/java

Enter to keep the current selection[+], or type selection number: 4
[ramansah@otodiginet ~]$ java -version
openjdk version "16.0.2" 2021-07-20
OpenJDK Runtime Environment (build 16.0.2+7-67)
OpenJDK 64-Bit Server VM (build 16.0.2+7-67, mixed mode, sharing)
[ramansah@otodiginet ~]$ 
Switch from Oracle Java 16 to openJDK 16
Switch from Oracle Java 16 to openJDK 16

Conclusion

We have installed Oracle Java 16 and also OpenJDK 16 on Rocky LInux 8 operating system successfuly.

Share this article via :

Leave a Reply

Your email address will not be published. Required fields are marked *