Java is a versatile, high-level, object-oriented programming language widely used for developing web, mobile, and cloud applications. Whether you’re creating games, chatbots, or other applications, Java provides a powerful and flexible platform. To get started with Java development on Rocky Linux 8, you’ll need to install the Java Development Kit (JDK). There are two main variants of JDK – OpenJDK and Oracle JDK. In this guide, we’ll walk you through the installation process for both OpenJDK 16 and Oracle JDK 16 on Rocky Linux 8.
Prerequisites
Before we begin, make sure you have the following:
- A server running Rocky Linux 8.
- Root access to the server.
Step 1: Update the System
First, it’s essential to update your system to ensure you have the latest packages. Open your terminal and run the following command:
dnf update -y
This command will update all the packages on your system. Once the update is complete, proceed to the next step.
Step 2: Install OpenJDK 16
To install OpenJDK 16, you’ll need to download it from the official website. Open your terminal and enter the following command to download OpenJDK 16:
curl -O https://download.java.net/java/GA/jdk16.0.2/d4a915d82b4c4fbb9bde534da945d746/7/GPL/openjdk-16.0.2_linux-x64_bin.tar.gz
This command will download the OpenJDK 16 package onto your system. Once the download is complete, extract the downloaded file using the following command:
tar -xvf openjdk-16.0.2_linux-x64_bin.tar.gz
Next, move the extracted directory to the /opt directory by running the following command:
mv jdk-16.0.2 /opt/
Now, you’ll need to add the Java path to the .bashrc file. Open the .bashrc file using a text editor:
nano ~/.bashrc
At the end of the file, add the following lines:
export JAVA_HOME=/opt/jdk-16.0.2 export PATH=$PATH:$JAVA_HOME/bin
Save and close the file. To activate the Java environment, run the following command:
source ~/.bashrc
Finally, verify the Java version by typing:
java --version
You should see the following output:
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)
Congratulations! You have successfully installed OpenJDK 16 on Rocky Linux 8.
Step 3: Install Oracle JDK 16
If you prefer to use Oracle JDK 16 instead of OpenJDK, follow these steps.
First, visit the Oracle Java website and obtain the download URL for Oracle JDK 16. In your terminal, use the following command to download the package:
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
Once the download is complete, install the downloaded file by running the following command:
rpm -ivh jdk-16.0.2_linux-x64_bin.rpm
After the installation is complete, set the Java path in the /etc/profile.d directory. Create a new file named java.sh
using a text editor:
nano /etc/profile.d/java.sh
Add the following line to the file, specifying the Oracle Java installation location:
JAVA_HOME="/usr/java/jdk-16.0.2/bin/java"
Save and close the file. To activate the Java environment variable, run the following command:
source /etc/profile
Finally, verify the Java version by typing:
java-version
You should see the following output:
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)
Congratulations! You have successfully installed Oracle JDK 16 on Rocky Linux 8.
Conclusion
In this guide, we have covered the installation process for both OpenJDK 16 and Oracle JDK 16 on Rocky Linux 8. You are now ready to start developing your Java applications on your Rocky Linux server.
Remember, whether you choose OpenJDK or Oracle JDK, both options provide a robust and feature-rich environment for Java development. Select the one that best suits your needs and preferences.
For reliable and scalable cloud hosting solutions, consider Shape.host’s Linux SSD VPS services. Shape.host offers high-performance virtual private servers optimized for Java development and other demanding workloads. With their exceptional uptime and excellent customer support, Shape.host ensures your Java applications run smoothly and securely.