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

  1. Stop all running Tomcat services before upgrading Java.

  2. Run the following command to stop the default Tomcat service:

    sudo systemctl stop tomcat.service
  3. If multiple Tomcat instances are running, stop each instance separately:

    sudo systemctl stop tomcat-ui
    sudo systemctl stop tomcat-job
  4. Verify the Tomcat service status:

    sudo systemctl status tomcat

Verify Current Java Version

  1. Verify the currently installed Java version before starting the upgrade.

  2. Run the following command:

  3. Expected output:

    Sample Reference Screenshot:

Back Up Existing cacerts File

Back up the existing cacerts file to preserve custom SSL certificates.

  1. Run the following command to create a backup directory:

  2. Navigate to the existing Java security directory and run the following command:

  3. Run the following command to back up the cacerts file:

    Sample Reference Screenshot:

  4. To verify backup, run the following command:

    Sample Reference Screenshot:

Update System Packages

  1. Update the Ubuntu package repository and installed packages.

  2. Run the following commands:

Install Java 21

  1. Install OpenJDK 21 using the Ubuntu package repository.

  2. Run the following command:

    Sample Reference Screenshot:

  3. Verify the installation:

    Sample Reference Screenshot:

Verify Installed Java Versions

  1. Verify all installed Java versions on the machine.

  2. Run the following command:

    Sample Reference Screenshot:

  3. Expected output:

Set Java 21 as the Default Version

  1. Configure Java 21 as the default Java version.

  2. Run the following command:

  3. Select the option corresponding to Java 21 from the displayed list. Sample Reference Screenshot:

Verify Java Upgrade

  1. Verify that the system is using Java 21 as the active Java version.

  2. Run the following command:

  3. Expected output:

Restore cacerts File

Restore the previously backed-up cacerts file into the Java 21 security directory.

Copy Backup cacerts File

  1. Run the following command:

Update File Permissions

  1. Set the required permissions for the restored file:

Update File Ownership

  1. Set the correct ownership for the restored file:

Verify Restored File

  1. Run the following command:

  2. Expected output:

Start Apache Tomcat Services

  1. Restart Apache Tomcat services after completing the Java upgrade.

  2. Run the following command:

  3. Verify the Tomcat service status:

  4. If multiple Tomcat instances are configured, start each service separately:


Copyright © 2026, OvalEdge LLC, Peachtree Corners, GA, USA.

Last updated

Was this helpful?