How to rollback or downgrade installed packages on Linux (RHEL / CentOS)

Let’s say we need to upgrade an existing PHP package to a higher version. If something goes wrong, what’s the option now? So we have an option in Linux where we can rollback a package to its previous version. Let’s see how to rollback and downgrade an update or package using the yum history undo command in Linux.

In the demo, we will install PHP 5.4, which is the default version in the Linux repository, and we will later update to a later version.

Let’s start the installation:

We will install PHP for our experiment and run the following commands to install PHP 5.4.

[[email protected] ~]# yum install php -y

You can check the version.

[[email protected] ~]# php -v
PHP 5.4.16 (cli) (built: Nov 1 2019 16:04:20) 
Copyright (c) 1997-2013 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2013 Zend Technologies

Upgrade PHP 5.4 to PHP 7.3:

Before installation, we will need to add Remi repository for PHP 7.3 on Linux using the following commands.

[[email protected] ~]# yum install epel-release -y
[[email protected] ~]# wget http://rpms.remirepo.net/enterprise/remi-release-7.rpm
[[email protected] ~]# rpm -ivh remi-release-7.rpm 
warning: remi-release-7.rpm: Header V4 DSA/SHA1 Signature, key ID 00f97f56: NOKEY
Preparing... ################################# [100%]
Updating / installing...
1:remi-release-7.7-2.el7.remi ################################# [100%]

you will see the Remi repository installed inside this /etc/yum.repos.d directory

[[email protected] ~]# vim /etc/yum.repos.d/remi-php73.repo
[remi-php73]
name=Remi's PHP 7.3 RPM repository for Enterprise Linux 7 - $basearch
#baseurl=http://rpms.remirepo.net/enterprise/7/php73/$basearch/
#mirrorlist=https://rpms.remirepo.net/enterprise/7/php73/httpsmirror
mirrorlist=http://cdn.remirepo.net/enterprise/7/php73/mirror
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-remi

Now you need to enable PHP7.3 repository and try to install using the same commands. Once this is done, check the installed version. This will update the previous version.

[[email protected] ~]# yum-config-manager --enable remi-php73
[[email protected] ~]# yum install php
[[email protected] ~]# php -v
PHP 7.3.17 (cli) (built: Apr 14 2020 08:29:22) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.3.17, Copyright (c) 1998-2018 Zend Technologies

Let’s assume that your application stopped working because it is compatible with version 7.3 and is not working right now. In this case, we will rollback the previous version 5.4.

DOWNLOAD PHP 7.3 BEFORE PHP 5.4:

We can check what we have installed or removed using yum commands. this keeps the yum history.

Итак, мы можем проверить, когда пакет был установлен и какой это был пакет.

When should you check what we have installed. So you can see there is an ID. we can use this ID to check what we have installed. we have installed PHP.

[[email protected] ~]# yum history list 6

If you need to check history ID 6, we can use the following commands.

[[email protected] ~]# yum history info 6

As you can see, the previous version has been updated to the new one. Now we have to downgrade or rollback it to a lower version.

You can version using any list:

yum list | grep php or rpm -qa | grep php

We’ll be using two different commands to downgrade a package, both work the same.

1.using down commands:

[[email protected] ~]# yum downgrade package_name.rpm

2. using the yum history commands. Yum syntax history undo id

[[email protected] ~]# yum history undo 6

As we can see, we have successfully downgraded the previous version. The above command will uninstall the current version and install the previous one.

[[email protected] ~]# php -v
PHP 5.4.16 (cli) (built: Nov 1 2019 16:04:20) 
Copyright (c) 1997-2013 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2013 Zend Technologies

That’s all!

Sidebar