How to Upgrade CentOS to a Newer Version

Updated: January 28, 2024 By: Guest Contributor Post a comment

Introduction

CentOS, or Community ENTerprise Operating System, is a Linux distribution that provides a free, enterprise-class computing platform. It is functionally compatible with its upstream source, Red Hat Enterprise Linux (RHEL). Upgrading CentOS to a newer version can be critical for security, performance improvements, and the latest software support. In this tutorial, we will cover the process of upgrading CentOS through several series of steps ranging from basic preparations to more advanced adjustments.

Prerequisites

  • A stable internet connection.
  • Access to the CentOS server as the root user or a user with sudo privileges.
  • Ensure there is a complete backup of the system.
  • Check the CentOS version by running cat /etc/centos-release.

Basic Upgrade Steps

1. Update Current Packages

Before proceeding with the upgrade, update all the existing packages to their latest available versions.

# Update packages
sudo yum update -y

Once the update process is complete, reboot the system to apply the updates:

# Reboot the system
sudo reboot

2. Install the EPEL Repository (If necessary)

The Extra Packages for Enterprise Linux (EPEL) repository provides additional quality software packages that are not included in the standard CentOS repositories.

# Install EPEL repository
sudo yum install epel-release -y

Upgrade Process

1. Removal of Obsolete Packages

Some packages will not have an updated version in the new CentOS release, and must be removed.

# Check for obsolete packages
rpm -qa | grep obsoletes

Remove any packages that are listed as a result of the above command:

# Remove obsolete packages
sudo yum remove package_name

2. Upgrading to a New CentOS Version

The standard approach to upgrading CentOS involves installing a set of upgrade tool packages, and then performing the upgrade.

# Install the CentOS Upgrade Tool
sudo yum install preupgrade-assistant-contents
sudo yum install redhat-upgrade-tool

Start the upgrade process:

# Begin Upgrade
sudo preupg --root=/ --force
sudo centos-upgrade-tool-cli --reboot

Follow the instructions and prompts to complete the upgrade process. The server will reboot and upgrade to the newer CentOS version.

Advanced Upgrade Considerations

1. Upgrading CentOS with Custom Kernels

If you have custom kernels installed, you need to be very careful during the upgrade process, as it may overwrite or remove these kernels. It is recommended to consult the documentation specific to your custom configuration.

2. Handling Third-Party Repositories

Ensure compatibility of third-party repositories with your new CentOS version, as these repositories might not automatically update:

# List enabled repositories
yum repolist enabled

# Disable third-party repositories
sudo yum-config-manager --disable repo_name

Then, you can check whether updated repositories for your new CentOS version are available and include them accordingly.

3. Transitioning to CentOS Stream

If you plan to upgrade to CentOS Stream, which is a rolling-release distribution considered a midway point between Fedora and RHEL, you need to adjust the repository:

# Install CentOS Stream
sudo dnf install centos-release-stream

# Switch from CentOS Linux to Stream
sudo dnf swap centos-{linux,stream}-repos
sudo dnf distro-sync

Troubleshooting

Upgrading a major operating system version can lead to unforeseen complications. If you encounter issues, you can consult the /var/log/centos-upgrade-tool.log for upgrade-specific logs, or use message boards and other community resources for help.

Conclusion

Upgrading CentOS to a newer version ensures that your systems stay secure and efficient, giving you access to the latest features and improvements. Always back up your system before attempting an upgrade and test the new version in a controlled environment prior to a full rollout.