Java is a popular programming language that is used for developing a wide range of applications, from web and mobile to enterprise and scientific applications. In this article, we will show you how to install the Java Development Kit (JDK) and the Java Runtime Environment (JRE) on Rocky Linux.
Prerequisites
Before we begin, make sure that you have the following:
- A Rocky Linux system with a non-root user with
sudo
privileges. - A stable internet connection.
Step 1: Update the System
First, update the package index and upgrade the installed packages by running the following command:
sudo dnf update
This will ensure that your system is up-to-date with the latest security patches and bug fixes.
Step 2: Install the Java Development Kit (JDK)
The Java Development Kit (JDK) is a package that contains the tools and libraries required for developing Java applications. It includes the Java compiler, the Java runtime environment (JRE), and the Java APIs.
To install the JDK on Rocky Linux, run the following command:
sudo dnf install java-1.8.0-openjdk-devel
This will install the OpenJDK 8 JDK package on your system.
To verify the installation, run the following command:
java -version
This will print the version number of the installed JDK, along with other details.
Step 3: Install the Java Runtime Environment (JRE)
The Java Runtime Environment (JRE) is a package that contains the Java Virtual Machine (JVM) and the Java libraries required for running Java applications.
To install the JRE on Rocky Linux, run the following command:
sudo dnf install java-1.8.0-openjdk
This will install the OpenJDK 8 JRE package on your system.
To verify the installation, run the following command:
java -version
This will print the version number of the installed JRE, along with other details.
Step 4: Set the Default Java Version
If you have multiple versions of Java installed on your system, you can use the update-alternatives
command to set the default Java version.
To list the available Java versions on your system, run the following command:
sudo update-alternatives --config java
This will print a list of available Java versions along with their corresponding paths.
To set the default Java version, run the following command:
sudo update-alternatives --config java
This will prompt you to select the default Java version from the available options. Select the desired Java version and press Enter
.
To verify the default Java version, run the following command:
java -version
This will print the version number of the default Java version, along with other details.
Conclusion
In this tutorial, we have shown you how to install the Java Development Kit (JDK) and the Java Runtime Environment (JRE) on Rocky Linux. We have also shown you how to set the default Java version using the update-alternatives
command. Java is a versatile programming language that is used for developing a wide range of applications. Try it out and see how it can help you build your next application.