Upgrading Java on your system is an essential step in ensuring that your environment is secure, efficient, and up-to-date. In this guide, we will show you how to upgrade OpenJDK 21 to OpenJDK 23 on Rocky Linux 9.5. This process involves checking the current Java version, installing the latest OpenJDK version, configuring the alternatives system, and verifying the upgrade by running a simple Java program
For a step-by-step visual guide, watch this video:
Step-by-Step Guide to Upgrade OpenJDK on Rocky Linux 9.5
Step 1: Check the Current Java Version
Before upgrading, it’s important to verify the current version of OpenJDK installed on your system. Open your terminal and execute the following command:
The output should look similar to this if OpenJDK 21 is installed:
You can also check the Java compiler version with:
This will give you details about the Java compiler installed on your system.
Step 2: Update System Repositories
Next, ensure that your system repositories are up-to-date. This ensures that you can access the latest packages available for your installation. Run the following command:
This will update your package list and install any available updates for your system.
Step 3: Install OpenJDK 23
Now it’s time to install OpenJDK 23. Run the following command to install both the runtime environment and development tools:
java-23-openjdk
includes the Java runtime environment.java-23-openjdk-devel
includes additional tools, such as the Java compiler (javac
).
In case OpenJDK 23 isn’t available in your default repositories, you might need to add a custom repository or download the RPM package directly from the OpenJDK website.
Step 4: Configure the Alternatives System
Once OpenJDK 23 is installed, you’ll need to configure the alternatives system to set it as the default version. This allows your system to use OpenJDK 23 for Java commands.
First, list the available Java versions by running:
This will display a list of installed Java versions. Type the number corresponding to OpenJDK 23 and press Enter.
You’ll also need to set OpenJDK 23 as the default Java compiler. Run:
Repeat the same process and select the OpenJDK 23 option.
Step 5: Set JAVA_HOME and PATH Variables
To ensure that Java is accessible system-wide, you need to set the JAVA_HOME
environment variable. First, find the installation path of OpenJDK 23:
This will return the full path of the Java executable. Copy this path for the next step.
Edit your .bashrc
file to set JAVA_HOME
and update the PATH
variable:
Add the following lines, replacing <path-to-java>
with the path you copied earlier:
To apply the changes, run:
This will reload the configuration, making JAVA_HOME
and PATH
available in your current terminal session.
Step 6: Verify the Upgrade
After the configuration, verify the upgrade by checking the Java version again:
Also, verify the Java compiler version:
Both commands should now display OpenJDK 23 as the default version.
Step 7: Test Java with a Simple Program
To ensure everything is working correctly, create a simple Java program. First, create a file named Test.java
:
Add the following code:
Save the file, then compile it with:
Run the program with:
If everything is set up correctly, you should see the output:
Conclusion
By following these steps, you’ve successfully upgraded OpenJDK from version 21 to version 23 on your Rocky Linux 9.5 system. You’ve also learned how to configure the system to use the new version and verified its functionality with a simple Java program. Keeping your Java environment up-to-date is crucial for security, performance, and compatibility with newer applications.
For a visual step-by-step guide, don’t forget to watch the video: How to Upgrade OpenJDK 21 to OpenJDK 23 on Rocky Linux 9.5.
If you have any questions or need further assistance, feel free to leave a comment below.
FAQs
Q1: How do I check which version of OpenJDK is currently installed on Rocky Linux?
Use the command java -version
to check the installed OpenJDK version.
Q2: What should I do if OpenJDK 23 is not available in my repositories?
You may need to add a custom repository or manually download the RPM package from the OpenJDK website.
Q3: Why is it important to set the JAVA_HOME
environment variable?
Setting JAVA_HOME
ensures that your system can locate Java and run Java-based applications properly.
Q4: Can I revert to OpenJDK 21 after upgrading to OpenJDK 23?
Yes, you can configure your system to use OpenJDK 21 again by selecting it from the alternatives system.
Q5: Is it safe to upgrade Java on a production system?
It’s recommended to test the upgrade in a staging environment first, as some applications may not be compatible with newer versions of Java.