December 3, 2021
How to install OpenJDK on Rocky Linux

How To Install Java (OpenJDK) On Rocky Linux 8

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

Introduction

If we have a mobile phone with various applications running on it, most likely these applications are built or run on the java platform. Java is the the most popular programming languages used to build many applications and systems. Java runs on all major operating systems and devices. In this article, we will learn how to install Java (OpenJDK 8 and OpenJDK 11) on a Rocky Linux 8 operating system. With Java installed on the system, we can install other applications that have any dependencies on Java applications.



But 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 that Oracle Java has a few additional commercial features.

OpenJDK Installation on Rocky Linux 8

Prerequisite

Before we are going to install OpenJDK on Rocky Linux 8, there are several prerequisite to be fulfilled, namely :

  • Rocky Linux 8 system with the latest package update
  • root account or ordinary account with sudo privilege
  • sufficient disk space good internet connection

OpenJDK 8 Installation On Rocky Linux 8

On this section we will show you how to install OpenJKD 8 on Rocky Linux 8 operating system. The installation starts by checking whether the system already has java installed or not, for this purpose we will submit the command line : java -version.

[ramansah@otodiginet ~]$ java -version
bash: java: command not found...

We will dowload by submitting command line : sudo dnf install -y java-1.8.0-openjdk-devel.

[ramansah@otodiginet ~]$ sudo dnf install -y java-1.8.0-openjdk-devel
[sudo] password for ramansah: 
Last metadata expiration check: 14:54:07 ago on Fri 13 Aug 2021 06:37:06 AM WIB.
Dependencies resolved.
====================================================================================================================
 Package                            Architecture  Version                                    Repository        Size
====================================================================================================================
Installing:
 java-1.8.0-openjdk-devel           x86_64        1:1.8.0.302.b08-0.el8_4                    appstream        9.8 M
Installing dependencies:
 copy-jdk-configs                   noarch        3.7-4.el8                                  appstream         26 k
 java-1.8.0-openjdk                 x86_64        1:1.8.0.302.b08-0.el8_4                    appstream        335 k
 java-1.8.0-openjdk-headless        x86_64        1:1.8.0.302.b08-0.el8_4                    appstream         34 M
 javapackages-filesystem            noarch        5.3.0-2.module+el8.3.0+125+5da1ae29        appstream         29 k
 lksctp-tools                       x86_64        1.0.18-3.el8                               baseos            98 k
 ttmkfdir                           x86_64        3.0.9-54.el8                               appstream         61 k
 tzdata-java                        noarch        2021a-1.el8                                appstream        190 k
 xorg-x11-fonts-Type1               noarch        7.5-19.el8                                 appstream        521 k
Enabling module streams:
 javapackages-runtime                             201801                                                           

Transaction Summary
====================================================================================================================
Install  9 Packages

Total download size: 45 M
Installed size: 160 M
Downloading Packages:
(1/9): copy-jdk-configs-3.7-4.el8.noarch.rpm                                         22 kB/s |  26 kB     00:01    
(2/9): java-1.8.0-openjdk-1.8.0.302.b08-0.el8_4.x86_64.rpm                           53 kB/s | 335 kB     00:06    
(3/9): javapackages-filesystem-5.3.0-2.module+el8.3.0+125+5da1ae29.noarch.rpm        30 kB/s |  29 kB     00:00    
(4/9): ttmkfdir-3.0.9-54.el8.x86_64.rpm                                              22 kB/s |  61 kB     00:02    
(5/9): tzdata-java-2021a-1.el8.noarch.rpm                                            17 kB/s | 190 kB     00:11    
(6/9): xorg-x11-fonts-Type1-7.5-19.el8.noarch.rpm                                    22 kB/s | 521 kB     00:24    
(7/9): lksctp-tools-1.0.18-3.el8.x86_64.rpm                                          70 kB/s |  98 kB     00:01    
(8/9): java-1.8.0-openjdk-devel-1.8.0.302.b08-0.el8_4.x86_64.rpm                     20 kB/s | 9.8 MB     08:23    
(9/9): java-1.8.0-openjdk-headless-1.8.0.302.b08-0.el8_4.x86_64.rpm                  49 kB/s |  34 MB     11:48    
Install OpenJDK 8 on Rocky Linux 8
Install OpenJDK 8 on Rocky Linux 8

At the end of installation we will got the message as shown below :

Installed:
  copy-jdk-configs-3.7-4.el8.noarch                                                                                 
  java-1.8.0-openjdk-1:1.8.0.302.b08-0.el8_4.x86_64                                                                 
  java-1.8.0-openjdk-devel-1:1.8.0.302.b08-0.el8_4.x86_64                                                           
  java-1.8.0-openjdk-headless-1:1.8.0.302.b08-0.el8_4.x86_64                                                        
  javapackages-filesystem-5.3.0-2.module+el8.3.0+125+5da1ae29.noarch                                                
  lksctp-tools-1.0.18-3.el8.x86_64                                                                                  
  ttmkfdir-3.0.9-54.el8.x86_64                                                                                      
  tzdata-java-2021a-1.el8.noarch                                                                                    
  xorg-x11-fonts-Type1-7.5-19.el8.noarch                                                                            

Complete!

The we will verify OpenJDK 8 installation by querying Java version with submit the command line : java -version.

[ramansah@otodiginet ~]$ java -version
openjdk version "1.8.0_302"
OpenJDK Runtime Environment (build 1.8.0_302-b08)
OpenJDK 64-Bit Server VM (build 25.302-b08, mixed mode)
Java version 8 (OpenJDK 1.8.0_302)
Java version 8 (OpenJDK 1.8.0_302)



OpenJDK 11 Installation On Rocky Linux 8

On this section we will show you how to install OpenJKD 11 on Rocky Linux 8 operating system. The installation is so simple since we have updated our Rocky Linux repository to the latest. For installing OpenJDK 11, we just submit the command line : sudo dnf install -y java-11-openjdk-devel.

[ramansah@otodiginet ~]$ sudo dnf install -y java-11-openjdk-devel
[sudo] password for ramansah: 
Last metadata expiration check: 1 day, 1:27:29 ago on Fri 13 Aug 2021 06:37:06 AM WIB.
Dependencies resolved.
================================================================================================================
 Package                            Architecture     Version                          Repository           Size
================================================================================================================
Installing:
 java-11-openjdk-devel              x86_64           1:11.0.12.0.7-0.el8_4            appstream           3.4 M
Installing dependencies:
 java-11-openjdk                    x86_64           1:11.0.12.0.7-0.el8_4            appstream           260 k
 java-11-openjdk-headless           x86_64           1:11.0.12.0.7-0.el8_4            appstream            39 M

Transaction Summary
================================================================================================================
Install  3 Packages

Total download size: 43 M
Installed size: 177 M
Downloading Packages:
(1/3): java-11-openjdk-11.0.12.0.7-0.el8_4.x86_64.rpm                           25 kB/s | 260 kB     00:10    A
(2/3): java-11-openjdk-devel-11.0.12.0.7-0.el8_4.x86_64.rpm                    219 kB/s | 3.4 MB     00:15    
(3/3): java-11-openjdk-headless-11.0.12.0.7-0.el8_4.x86_64.rpm                 1.0 MB/s |  39 MB     00:38    
---------------------------------------------------------------------------------------------------------------
Total                                                                          994 kB/s |  43 MB     00:44     
Install OpenJDK 11 on Rocky Linux 8
Install OpenJDK 11 on Rocky Linux 8

Until this stage, we have two versions of OpenJDK, namely: OpenJDK 8 and OpenJDK 11. To verify and select the default Java to be used on our system. We can use the command line: sudo alternatives --config java.

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

There are 2 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)

Enter to keep the current selection[+], or type selection number: 2
OpenJDK 11
OpenJDK 11

So far, we have installed two Java version on Rocky Linux 8 operating system, namely : OpenJDK 8 and OpenJDK 11. Then we have two options in using Java on our system.

Conclussion

We have learnt how to install OpenJDK 8 and OpenJDK 11 on Rocky Linux 8. And we also has been and switch between them smoothly.

Share this article via :

Leave a Reply

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