How to Upgrade OpenJDK 11 to OpenJDK 17 on Rocky Linux 9.5

In this blog, we’ll guide you step-by-step to upgrade OpenJDK 11 to OpenJDK 17 on Rocky Linux 9.5, including installation, configuration, and testing with a sample Java program. Upgrading OpenJDK 11 to OpenJDK 17 on Rocky Linux is a vital step to keep your Java environment secure and optimized. OpenJDK 17, being a long-term support (LTS) version, offers improved performance, enhanced security, and modern features for Java development. Watch the process in our YouTube video.


Steps to upgrade OpenJDK 11 to OpenJDK 17 on Rocky Linux

Prerequisites:

To upgrade OpenJDK 11 to OpenJDK 17 on Rocky Linux, ensure you meet these requirements:

  • A system running Rocky Linux 9.5 with sudo access.
  • An active internet connection.
  • Basic Linux terminal command knowledge.

To confirm your OS version, run:

cat /etc/*-release  

Step 1: Check Current Java Version

Before upgrading OpenJDK 11 to OpenJDK 17 on Rocky Linux, verify your current Java version:

java -version  
javac -version  

This step ensures you identify the current configuration. Compatibility testing is advised if legacy applications rely on Java 11 features.


Step 2: Install OpenJDK 17 on Rocky Linux

Install OpenJDK 17 along with development tools using the DNF package manager:

sudo dnf install java-17-openjdk java-17-openjdk-devel -y  

Step 3: Configure Java and Javac Alternatives

To complete the upgrade from OpenJDK 11 to OpenJDK 17 on Rocky Linux, configure the default versions:

sudo alternatives --config java  
sudo alternatives --config javac  

Step 4: Set JAVA_HOME and Update PATH Variables

  1. Retrieve the Java installation path:
    readlink -f $(which java)  
    
  2. Set the JAVA_HOME environment variable and update PATH in .bashrc:
    echo "export JAVA_HOME=/usr/lib/jvm/java-17-openjdk" >> ~/.bashrc  
    echo "export PATH=$JAVA_HOME/bin:$PATH" >> ~/.bashrc  
    source ~/.bashrc  
    

Reload .bashrc to apply the changes:

source ~/.bashrc  

Step 5: Verify OpenJDK 17 Installation on Rocky Linux

Confirm that OpenJDK 17 is installed correctly:

java -version  
javac -version  
echo $JAVA_HOME  

Step 6: Test OpenJDK 17 with a Sample Java Program

Validate your upgrade to OpenJDK 17 on Rocky Linux by running a Java program.

Create HelloWorld.java:

public class HelloWorld {  
    public static void main(String[] args) {  
        System.out.println("Hello, World! OpenJDK 17 is working perfectly!");  
    }  
}  

Compile and run the program:

javac HelloWorld.java  
java HelloWorld  

Output:

Hello, World! OpenJDK 17 is working perfectly!  

FAQs About Upgrading OpenJDK 11 to OpenJDK 17 on Rocky Linux

Q1: Why should I upgrade OpenJDK 11 to OpenJDK 17 on Rocky Linux?
A1: OpenJDK 17 is an LTS version offering better security, stability, and performance for Java applications.

Q2: Can I keep both OpenJDK 11 and 17?
A2: Yes, you can switch between versions using the alternatives command.

Q3: Will the upgrade affect my existing applications?
A3: Test in a staging environment to avoid compatibility issues with legacy applications.

Q4: How do I roll back to OpenJDK 11?
A4: Reinstall OpenJDK 11 using the DNF package manager and reconfigure alternatives.

Q5: Is OpenJDK 17 production-ready?
A5: Yes, OpenJDK 17 is ideal for production as it is an LTS version.


Conclusion
You’ve successfully upgraded OpenJDK 11 to OpenJDK 17 on Rocky Linux 9.5. By following this guide, you’ve ensured your system is ready for modern Java development. For a complete demonstration, watch our step-by-step tutorial in this video. Don’t forget to like, share, and subscribe for more Linux and DevOps guides!

See also:

List of monitoring tools 

Linux Blogs

AWS Cloud Blogs

Database Blogs

DevOps Blogs

Interview Questions & Answers

Docker Blogs

Google Cloud Blogs







Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.