How to Undo a Yum Update

By | 2021-10-16

While uncommon, sometimes a package update can cause problems. Distributions that use yum or dnf track package changes with a transaction log. You can undo a yum update by undoing the relevant transaction(s).

In order for this to work, the previous versions of any packages in the transaction must exist in the repositories.

The process is relatively simple. I will demonstrate the process by installing an update on a CentOS 8 VM, then undoing the transaction. If you are using a newer system that uses dnf, the process should work the same as demonstrated.

For those in a hurry, it is only two steps.

  1. yum history
  2. yum history rollback 8

Replace 8 with the transaction you want to roll your system back to. The transaction number you use will install the packages as they were after the transaction number specified. I.e. using 8 will undo all transaction numbers (9 and up) that have happened since then, but 8 will not be undone.

Demonstration

First, I will show the OS I am using, and the current version of a package:

# cat /etc/redhat-release 
CentOS Linux release 8.4.2105
# rpm -q rpm
rpm-4.14.3-13.el8.x86_64

Now I upgrade the package to the latest version:

# yum upgrade rpm # output omitted
# rpm -q rpm
rpm-4.14.3-14.el8_4.x86_64

Get the Transaction Number

Next, get the transaction number. Use yum history to display the transaction history.

# yum history
ID     | Command line              | Date and time    | Action(s)      | Altered
--------------------------------------------------------------------------------
    11 | upgrade rpm               | 2021-10-15 18:58 | Upgrade        |    6   
    10 | install rpm-4.14.3-13.el8 | 2021-10-15 18:58 | Downgrade      |    6   
     9 | update                    | 2021-10-15 18:51 | E, I, U        |  205  

If you aren’t sure what happened in a particular transaction, you can get more details with yum history info. For example, I want to know more info about the package changes with transaction 11:

# yum history info 11
Transaction ID : 11
Begin time     : Fri 15 Oct 2021 06:58:53 PM EDT
Begin rpmdb    : 404:4c71f64a5ad4a6d91ab422914b852a1493644b25
End time       : Fri 15 Oct 2021 06:58:55 PM EDT (2 seconds)
End rpmdb      : 404:bf3c5635380a96b7fb49c9e37fbfd2cf68858948
User           : root 
Return-Code    : Success
Releasever     : 8
Command Line   : upgrade rpm
Comment        : 
Packages Altered:
    Upgrade  python3-rpm-4.14.3-14.el8_4.x86_64                @baseos
    Upgraded python3-rpm-4.14.3-13.el8.x86_64                  @@System
    Upgrade  rpm-4.14.3-14.el8_4.x86_64                        @baseos
    Upgraded rpm-4.14.3-13.el8.x86_64                          @@System
    Upgrade  rpm-build-libs-4.14.3-14.el8_4.x86_64             @baseos
    Upgraded rpm-build-libs-4.14.3-13.el8.x86_64               @@System
    Upgrade  rpm-libs-4.14.3-14.el8_4.x86_64                   @baseos
    Upgraded rpm-libs-4.14.3-13.el8.x86_64                     @@System
    Upgrade  rpm-plugin-selinux-4.14.3-14.el8_4.x86_64         @baseos
    Upgraded rpm-plugin-selinux-4.14.3-13.el8.x86_64           @@System
    Upgrade  rpm-plugin-systemd-inhibit-4.14.3-14.el8_4.x86_64 @baseos
    Upgraded rpm-plugin-systemd-inhibit-4.14.3-13.el8.x86_64   @@System

Rollback the Transaction

Use yum history rollback to return the system to the state it was in at that transaction number. In this demonstration, I want it be as it was before upgrading the rpm package. The most recent transaction is 11, so I will use transaction 10.

# yum history rollback 10
Last metadata expiration check: 0:10:33 ago on Fri 15 Oct 2021 06:49:34 PM EDT.
Dependencies resolved.
================================================================================
 Package                        Arch       Version             Repository  Size
================================================================================
Downgrading:
 python3-rpm                    x86_64     4.14.3-13.el8       baseos     158 k
 rpm                            x86_64     4.14.3-13.el8       baseos     542 k
 rpm-build-libs                 x86_64     4.14.3-13.el8       baseos     155 k
 rpm-libs                       x86_64     4.14.3-13.el8       baseos     339 k
 rpm-plugin-selinux             x86_64     4.14.3-13.el8       baseos      76 k
 rpm-plugin-systemd-inhibit     x86_64     4.14.3-13.el8       baseos      77 k

Transaction Summary
================================================================================
Downgrade  6 Packages

Total download size: 1.3 M
Is this ok [y/N]: 

After rolling back the transaction, run yum history to verify.

# yum history
ID     | Command line              | Date and time    | Action(s)      | Altered
--------------------------------------------------------------------------------
    12 | history rollback 10       | 2021-10-15 19:00 | Downgrade      |    6   
    11 | upgrade rpm               | 2021-10-15 18:58 | Upgrade        |    6   
    10 | install rpm-4.14.3-13.el8 | 2021-10-15 18:58 | Downgrade      |    6 

As you can see, the package in question is the version it was before the upgrade at the beginning of the demonstration:

# rpm -q rpm
rpm-4.14.3-13.el8.x86_64

References

See Also