Java Upgrade 21.x (Ubuntu)
This article provides step-by-step instructions to upgrade Java from JDK 17 to JDK 21 on an Ubuntu machine. It includes procedures for stopping Apache Tomcat services, installing Java 21, updating the default Java version, and restoring SSL certificates from the existing Java installation. The article also covers verification steps to ensure the upgraded Java version integrates successfully with Apache Tomcat services. This upgrade helps maintain compatibility, security, and performance for OvalEdge deployments and related services.
Prerequisites
Complete the following prerequisites before starting the upgrade:
Ensure sudo or root access is available on the Ubuntu machine.
Back up the existing Java options and heap settings configured for Apache Tomcat services.
Stop all Tomcat services before starting the upgrade.
Ensure internet access is available to download the required JDK packages.
Verify sufficient disk space is available for installation.
Validate Java 17 and Java 21 compatibility requirements for Elasticsearch 9.x before starting the upgrade.
Stop Apache Tomcat Services
Stop all running Tomcat services before upgrading Java.
Run the following command to stop the default Tomcat service:
sudo systemctl stop tomcat.serviceIf multiple Tomcat instances are running, stop each instance separately:
sudo systemctl stop tomcat-ui sudo systemctl stop tomcat-jobVerify the Tomcat service status:
sudo systemctl status tomcat
Verify Current Java Version
Verify the currently installed Java version before starting the upgrade.
Run the following command:
Expected output:
Sample Reference Screenshot:

Back Up Existing cacerts File
Back up the existing cacerts file to preserve custom SSL certificates.
Run the following command to create a backup directory:
Navigate to the existing Java security directory and run the following command:
Run the following command to back up the cacerts file:
Sample Reference Screenshot:

To verify backup, run the following command:
Sample Reference Screenshot:

Update System Packages
Update the Ubuntu package repository and installed packages.
Run the following commands:
Install Java 21
Install OpenJDK 21 using the Ubuntu package repository.
Run the following command:
Sample Reference Screenshot:

Verify the installation:
Sample Reference Screenshot:

Verify Installed Java Versions
Verify all installed Java versions on the machine.
Run the following command:
Sample Reference Screenshot:

Expected output:
Set Java 21 as the Default Version
Configure Java 21 as the default Java version.
Run the following command:
Select the option corresponding to Java 21 from the displayed list. Sample Reference Screenshot:

Verify Java Upgrade
Verify that the system is using Java 21 as the active Java version.
Run the following command:
Expected output:
Restore cacerts File
Restore the previously backed-up cacerts file into the Java 21 security directory.
Copy Backup cacerts File
Run the following command:
Update File Permissions
Set the required permissions for the restored file:
Update File Ownership
Set the correct ownership for the restored file:
Verify Restored File
Run the following command:
Expected output:
Start Apache Tomcat Services
Restart Apache Tomcat services after completing the Java upgrade.
Run the following command:
Verify the Tomcat service status:
If multiple Tomcat instances are configured, start each service separately:
Copyright © 2026, OvalEdge LLC, Peachtree Corners, GA, USA.
Last updated
Was this helpful?

