How to Install JDK on Rocky Linux

thelinuxterminal

Author - Sanjay

Introduction

Java is one of the most popular programming languages currently used in the industry Java is free and open source so as JDK , JDK is open source software development kit used to build applications using Java. has a lot of tools that are used for developing and testing Java based applications like JRE , JDK,JSTACK .

JDK is completely owned by Oracle Java licence permits only non commercial use of Java for building applications and software development where is open JDK is in open source implementation of the Java Platform.

There two different types of implementations of Java open JDK and Oracle Java there is almost no difference between them except at Oracle SQL additional components and features.

in this tutorial we are going to install install and set up one or more versions of Java in rocky Linux

There are two variety of ways with which you can install JDK in rocky Linux.

Table of Contents

Pre-Requisistes

In order to start with the installation of Rocky Linux we need to have Rocky Linux installed .

Install open JDK 11

In order to install open JDK 11 , we need to check if open jdk is already present of not . You can do it by following command

sudo dnf search jdk 11

The output of the command will have the list of all the open JDK is available in your repository

Boot Menu Rocky Linux

As you see below there are various versions of JDK available we are going to use the open JDK development version As below .

sudo dnf install java-18-openjdk-devel

Verify Java is Installed on your server

The following command will help you verifying if java is installed on your server .

[root@thelinuxterminal ~]# java -version

Output

openjdk version "11.0.12" 2021-07-20 LTS
OpenJDK Runtime Environment 18.9 (build 11.0.12+7-LTS)
OpenJDK 64-Bit Server VM 18.9 (build 11.0.12+7-LTS, mixed mode, sharing)

Installing Java 8 from Oracle

Now that we have installed open JDK 11 we need to install Java 8 so you can install Java 8 by following the same method above but in this case we are going to install Oracle Java 8 version

Download JDK 8

In order to download JDK 8 you need to visit the Oracle . Java 8 download page

JDK 8 Download Rocky Linux We are going to download the rpm package .

Installing JDK 8

Once the package is downloaded you can install it by typing following command .

[root@thelinuxt ~]# sudo dnf install /home/thelinuxt/Downloads/jdk-8u301-linux-aarch64.rpm

Once the installation is completed , you can check the Java version

java -version

Switching between Multiple JDK versions

Now that we have installed two different versions of JDK on our system ,we might need to use specific JDK versions for specific applications .

So in this case we might need to switch between different JDK versions we are going to check how we can switch between different JDK versions on your Rocky Linux server .

In order to switch between JDK 8 and JDK 11 execute the following command

[root@thelinuxt ~]# sudo alternatives --config java

Output

There are 2 programs which provide 'java'.

  Selection    Command
-----------------------------------------------
   1           java-11-openjdk.x86_64 (/usr/lib/jvm/java-11-openjdk-11.0.12.0.7-0.el8_4.x86_64/bin/java)
*+ 2           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)

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

if you see e a star followed by a plus sign denotes that this is the current version of Java installed on your Rocky Linux server .If you want to switch between the versions you have to select the number denoted above .

In this case i type 1 . Now verify you java version . You will get the current version you have selected as shown below.

Updating Java Versions

Conclusion

We have installed JDK on Rocky Linux 8 , there are two different ways we have seen . Please mention if you need any help here .