Sometime we need to uninstall packages or roll back packages installed in Redhat/CentOS/Fedora Systems. So we can perform these things with “yum” command. In this post we will how we could perform these rollback or uninstall procedure. HowTo use yum history rollback update inside Red_Hat_Enterprise_Linux

There is another post for yum contain details usage of yum command.

We can perform these things with yum remove command as well but this will only uninstall particular packages, undo process will revert complete process once again as it is mentioned in yum history info. Let’s see how we can perform these things in CentOS7 machine.

Setup

[root@mysql-pri ~]# cat /etc/redhat-release 
CentOS Linux release 7.4.1708 (Core) 

[root@mysql-pri ~]# uname  -r
3.10.0-693.2.2.el7.x86_64

[root@mysql-pri ~]# yum --version
3.4.3
  Installed: rpm-4.11.3-25.el7.x86_64 at 2017-09-25 14:42
  Built    : CentOS BuildSystem  at 2017-08-03 03:48
  Committed: Panu Matilainen  at 2017-03-17

  Installed: yum-3.4.3-154.el7.centos.noarch at 2017-09-25 14:43
  Built    : CentOS BuildSystem  at 2017-08-05 19:13
  Committed: CentOS Sources  at 2017-08-01

  Installed: yum-plugin-fastestmirror-1.1.31-42.el7.noarch at 2017-09-25 14:43
  Built    : CentOS BuildSystem  at 2017-08-11 10:23
  Committed: Valentina Mukhamedzhanova  at 2017-03-21

Now let’s see how to do this procedure ..

[root@mysql-pri ~]# yum history
Loaded plugins: fastestmirror
ID     | Login user               | Date and time    | Action(s)      | Altered
-------------------------------------------------------------------------------
     7 | root               | 2017-09-26 19:04 | Install        |    2   
     6 | root               | 2017-09-25 22:54 | Install        |    1   
     5 | root               | 2017-09-25 20:11 | I, O, U        |  285 EE
     4 | root               | 2017-09-25 03:26 | Install        |    1   
     3 | root               | 2017-04-30 13:04 | Install        |   16   
     2 | root               | 2017-04-30 12:21 | Install        |   31   
     1 | System            | 2017-04-30 12:13 | Install        |  297   
history list

This is Machine yum history, i did some of installation and update through yum command. Let’s work on one of transactions id.
In case you like to search more on yum command usage and options, read this post

[root@mysql-pri ~]# yum history info 7
Loaded plugins: fastestmirror
Transaction ID : 7
Begin time     : Tue Sep 26 19:04:49 2017
Begin rpmdb    : 374:b1d280862bdbce5e9f3ed260508bf3ecb4febe57
End time       :                           (0 seconds)
End rpmdb      : 376:5c5a1cc3e8ad588d2b8f0598d952829094e07a21
User           : root 
Return-Code    : Success
Command Line   : install bind-utils
Transaction performed with:
    Installed     rpm-4.11.3-25.el7.x86_64                      @base
    Installed     yum-3.4.3-154.el7.centos.noarch               @base
    Installed     yum-plugin-fastestmirror-1.1.31-42.el7.noarch @base
Packages Altered:
    Dep-Install bind-libs-32:9.9.4-51.el7.x86_64  @updates
    Install     bind-utils-32:9.9.4-51.el7.x86_64 @updates
history info

So as per Machine records, bind-utils get installed on 7th transaction. So Let’s revert it back.

[root@mysql-pri ~]# yum history undo 7
Loaded plugins: fastestmirror
Undoing transaction 7, from Tue Sep 26 19:04:49 2017
    Dep-Install bind-libs-32:9.9.4-51.el7.x86_64  @updates
    Install     bind-utils-32:9.9.4-51.el7.x86_64 @updates
Resolving Dependencies
--> Running transaction check
---> Package bind-libs.x86_64 32:9.9.4-51.el7 will be erased
---> Package bind-utils.x86_64 32:9.9.4-51.el7 will be erased
--> Finished Dependency Resolution

Dependencies Resolved

========================================================================================
 Package                   Arch           Version               Repository         Size
========================================================================================
Removing:
 bind-libs                 x86_64         32:9.9.4-51.el7       @updates          2.6 M
 bind-utils                x86_64         32:9.9.4-51.el7       @updates          435 k

Transaction Summary
========================================================================================
Remove  2 Packages

Installed size: 3.0 M
Is this ok [y/N]: y
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Erasing    : 32:bind-utils-9.9.4-51.el7.x86_64                                                                                                                                         1/2 
  Erasing    : 32:bind-libs-9.9.4-51.el7.x86_64                                                                                                                                          2/2 
  Verifying  : 32:bind-utils-9.9.4-51.el7.x86_64                                                                                                                                         1/2 
  Verifying  : 32:bind-libs-9.9.4-51.el7.x86_64                                                                                                                                          2/2 

Removed:
  bind-libs.x86_64 32:9.9.4-51.el7    bind-utils.x86_64 32:9.9.4-51.el7                                                            

Complete!

This way we can revert back installation and update process in safe manner. One thing i noticed that it is not 100% accurate, sometime it is not possible for undo process to revert complete process. It good to revert back for packages removal. But if we update whole system with “yum update” command, this will not work properly or reject at initial process.