Upgrade OpenJDK 17 to OpenJDK 21 on Rocky Linux with this detailed guide to ensure your Java environment stays updated with the latest features and security improvements. Follow these steps to complete the upgrade seamlessly, and watch this video for a visual walkthrough.
Why Upgrade OpenJDK 17 to OpenJDK 21 on Rocky Linux?
Staying up to date with the latest Java versions, like OpenJDK 21, brings improved performance, security patches, and new features. This guide will help developers and administrators perform the upgrade without complications.
How to Upgrade OpenJDK 17 to OpenJDK 21 on Rocky Linux
Step 1: Verify Your Current OpenJDK Version
Before starting, check which version of OpenJDK is installed on your system:
This will confirm whether you are currently using OpenJDK 17.
Step 2: Update Your System and Enable EPEL Repository
Run the following commands to ensure your system is up to date and the EPEL repository is enabled:
Installing OpenJDK 21 on Rocky Linux
Run the following command to install OpenJDK 21:
If you’re a developer, install the java-21-openjdk-devel
package for compiling Java programs:
Configuring OpenJDK 21 as Default (Alternatives)
Step 3: Configure Alternatives for Java and Javac
Set OpenJDK 21 as the default Java version:
Select the option for OpenJDK 21. Repeat the process for javac
:
Step 4: Set JAVA_HOME and Update PATH
Add the JAVA_HOME environment variable to your .bashrc
file:
Verifying OpenJDK 21 Installation
Run these commands to confirm the installation:
Test OpenJDK 21 with a Sample Program
Create a test file named Test.java
:
Compile and run the program:
You should see the output:
Java 21 setup is working!
FAQs
1. Why should I upgrade OpenJDK 17 to OpenJDK 21 on Rocky Linux?
Upgrading ensures access to new Java features, better performance, and improved security.
2. Is OpenJDK 21 compatible with all applications?
Some older applications may not support newer Java versions. Test in a staging environment first.
3. How do I switch back to OpenJDK 17 if needed?
Use the sudo alternatives
command to switch between installed versions.
4. Do I need java-21-openjdk-devel
for development?
Yes, the java-21-openjdk-devel
package includes development tools like the Java compiler.
5. What’s the difference between java-21-openjdk
and java-21-openjdk-devel
?
The java-21-openjdk
package provides the runtime environment, while the -devel
package includes development tools.
Conclusion
Upgrading OpenJDK 17 to OpenJDK 21 on Rocky Linux ensures your system is secure and ready for modern Java development. Follow this guide and watch this video for additional clarity. Subscribe for more Linux tutorials!