AlmaLinux or RockyLinux are enterprise Linux operating systems and perfect choices for hosting or running server applications. They are free and open source, so anyone can use them to set up their Linux infrastructure. However, the default Java available through their repositories is OpenJDK which is an open-source edition of Oracle Java. Therefore, for those who are looking for commands for installing Oracle Java version 8 which is long-term supported either on Almalinux or Rocky Linux 8/9, then in this tutorial, we learn how to do that.
Step 1: Download Oracle Java 8
We cannot get Oracle Java 8 directly using the DNF package manager of Almalinux or Rocky because it is not present there, hence, visit the official website and download the JDK or JRE 8 whatever you want to install as per your system architecture (x64 or x86). Here, we are downloading the 64-bit version.
Step 2: Change file Permission to execute it
Once you have downloaded the file and it is on the system, let’s change its permission to execute and install Java 8 without any problem.
Switch to the directory where the file is located and run:
sudo chmod a+x file-name
sudo chmod a+x jdk-8u*-linux-x64.rpm
Step 3: Install Oracle JDK 8 on Almalinux or RockyLinux
Once you have made the files executable, use the RPM command to install the JDK or JRE 8 on the system.
sudo rpm -ivh jdk-8u*-linux-x64.rpm
Step 4: Check Version
To confirm, whether the version of Java you have installed is on your system or not, we can use the given command.
However, if you have multiple versions of Java installed then the latest and default one will appear in the result of the above command. Hence, to make the Oracle Java 8 your system’s default version,if not already, follow the next step.
Step 5: Update Alternatives
Updat the Alternatives to set the default version of Java as per your project. For example, if you have multiple version along with Oracle Java 8 then to configure it as the system wide default use the given command:
sudo update-alternatives --config java
The above command will list the installed versions of Java on your Linux system. It will also ask you which version of it you want to be the default. Enter the Selection number and hit the enter key.
Similary, those want to change the Java Compiler – Javac as well can use the following command:
sudo update-alternatives --config javac
Uninstallating Java, if required
If there are circumstances, when you don’t require Oracle Java 8 on your system then to completely remove it from AlmaLinux or Rocky, run the given command:
sudo dnf remove jdk-1.8