Sling Academy
Home/DevOps/How to Upgrade CentOS to a Newer Version

How to Upgrade CentOS to a Newer Version

Last updated: January 28, 2024

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.

Next Article: How to take a snapshot of a disk in VirtualBox (and restore it later)

Previous Article: How to Completely Uninstall Homebrew and Remove All Its Files

Series: Linux Tutorials

DevOps

You May Also Like

  • How to reset Ubuntu to factory settings (4 approaches)
  • Making GET requests with cURL: A practical guide (with examples)
  • Git: What is .DS_Store and should you ignore it?
  • NGINX underscores_in_headers: Explained with examples
  • How to use Jenkins CI with private GitHub repositories
  • Terraform: Understanding State and State Files (with Examples)
  • SHA1, SHA256, and SHA512 in Terraform: A Practical Guide
  • CSRF Protection in Jenkins: An In-depth Guide (with examples)
  • Terraform: How to Merge 2 Maps
  • Terraform: How to extract filename/extension from a path
  • JSON encoding/decoding in Terraform: Explained with examples
  • Sorting Lists in Terraform: A Practical Guide
  • Terraform: How to trigger a Lambda function on resource creation
  • How to use Terraform templates
  • Understanding terraform_remote_state data source: Explained with examples
  • Jenkins Authorization: A Practical Guide (with examples)
  • Solving Jenkins Pipeline NotSerializableException: groovy.json.internal.LazyMap
  • Understanding Artifacts in Jenkins: A Practical Guide (with examples)
  • Using Jenkins with AWS EC2 and S3: A Practical Guide