首先使用 yum history list 获取历史 ID

再用 yum history undo 进行操作

示例,比如卸载个 Docker

Q: 为什么要卸载 Docker?

A: 我只是随便玩玩。

$ yum history list docker
Loaded plugins: fastestmirror
ID     | Command line             | Date and time    | Action(s)      | Altered
-------------------------------------------------------------------------------
    45 | install docker           | 2017-05-28 12:17 | I, U           |   27 EE
history list

$ yum history undo 45

Loaded plugins: fastestmirror
Undoing transaction 45, from Sun May 28 12:17:27 2017
    Updated     audit-2.6.5-3.el7.x86_64                               @anaconda
    Update            2.6.5-3.el7_3.1.x86_64                           @updates
    Updated     audit-libs-2.6.5-3.el7.x86_64                          @anaconda
    Update                 2.6.5-3.el7_3.1.x86_64                      @updates
    Dep-Install audit-libs-python-2.6.5-3.el7_3.1.x86_64               @updates
    Dep-Install checkpolicy-2.5-4.el7.x86_64                           @base
    Dep-Install container-selinux-2:2.12-2.gite7096ce.el7.noarch       @extras
    Updated     device-mapper-7:1.02.135-1.el7.x86_64                  @anaconda
    Update                    7:1.02.135-1.el7_3.4.x86_64              @updates
    Dep-Install device-mapper-event-7:1.02.135-1.el7_3.4.x86_64        @updates
    Dep-Install device-mapper-event-libs-7:1.02.135-1.el7_3.4.x86_64   @updates
    Updated     device-mapper-libs-7:1.02.135-1.el7.x86_64             @anaconda
    Update                         7:1.02.135-1.el7_3.4.x86_64         @updates
    Dep-Install device-mapper-persistent-data-0.6.3-1.el7.x86_64       @base
    Install     docker-2:1.12.6-28.git1398f24.el7.centos.x86_64        @extras
    Dep-Install docker-client-2:1.12.6-28.git1398f24.el7.centos.x86_64 @extras
    Dep-Install docker-common-2:1.12.6-28.git1398f24.el7.centos.x86_64 @extras
    Dep-Install libcgroup-0.41-11.el7.x86_64                           @base
    Dep-Install libseccomp-2.3.1-2.el7.x86_64                          @base
    Updated     libsemanage-2.5-4.el7.x86_64                           @anaconda
    Update                  2.5-5.1.el7_3.x86_64                       @updates
    Dep-Install libsemanage-python-2.5-5.1.el7_3.x86_64                @updates
    Dep-Install lvm2-7:2.02.166-1.el7_3.4.x86_64                       @updates
    Dep-Install lvm2-libs-7:2.02.166-1.el7_3.4.x86_64                  @updates
    Dep-Install oci-register-machine-1:0-3.11.gitdd0daef.el7.x86_64    @extras
    Dep-Install oci-systemd-hook-1:0.1.7-2.git2788078.el7.x86_64       @extras
    Updated     policycoreutils-2.5-8.el7.x86_64                       @anaconda
    Update                      2.5-11.el7_3.x86_64                    @updates
    Dep-Install policycoreutils-python-2.5-11.el7_3.x86_64             @updates
    Dep-Install python-IPy-0.75-6.el7.noarch                           @base
    Dep-Install setools-libs-3.3.8-1.1.el7.x86_64                      @base
    Dep-Install skopeo-containers-1:0.1.19-1.el7.x86_64                @extras
    Dep-Install yajl-2.0.4-4.el7.x86_64                                @base
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyuncs.com
 * epel: mirrors.aliyuncs.com
 * extras: mirrors.aliyuncs.com
 * updates: mirrors.aliyuncs.com
Resolving Dependencies
--> Running transaction check
---> Package audit.x86_64 0:2.6.5-3.el7 will be a downgrade
---> Package audit.x86_64 0:2.6.5-3.el7_3.1 will be erased
---> Package audit-libs.x86_64 0:2.6.5-3.el7 will be a downgrade
---> Package audit-libs.x86_64 0:2.6.5-3.el7_3.1 will be erased
---> Package audit-libs-python.x86_64 0:2.6.5-3.el7_3.1 will be erased
---> Package checkpolicy.x86_64 0:2.5-4.el7 will be erased
---> Package container-selinux.noarch 2:2.12-2.gite7096ce.el7 will be erased
---> Package device-mapper.x86_64 7:1.02.135-1.el7 will be a downgrade
---> Package device-mapper.x86_64 7:1.02.135-1.el7_3.4 will be erased
---> Package device-mapper-event.x86_64 7:1.02.135-1.el7_3.4 will be erased
---> Package device-mapper-event-libs.x86_64 7:1.02.135-1.el7_3.4 will be erased
---> Package device-mapper-libs.x86_64 7:1.02.135-1.el7 will be a downgrade
---> Package device-mapper-libs.x86_64 7:1.02.135-1.el7_3.4 will be erased
---> Package device-mapper-persistent-data.x86_64 0:0.6.3-1.el7 will be erased
---> Package docker.x86_64 2:1.12.6-28.git1398f24.el7.centos will be erased
---> Package docker-client.x86_64 2:1.12.6-28.git1398f24.el7.centos will be erased
---> Package docker-common.x86_64 2:1.12.6-28.git1398f24.el7.centos will be erased
---> Package libcgroup.x86_64 0:0.41-11.el7 will be erased
---> Package libseccomp.x86_64 0:2.3.1-2.el7 will be erased
---> Package libsemanage.x86_64 0:2.5-4.el7 will be a downgrade
---> Package libsemanage.x86_64 0:2.5-5.1.el7_3 will be erased
---> Package libsemanage-python.x86_64 0:2.5-5.1.el7_3 will be erased
---> Package lvm2.x86_64 7:2.02.166-1.el7_3.4 will be erased
---> Package lvm2-libs.x86_64 7:2.02.166-1.el7_3.4 will be erased
---> Package oci-register-machine.x86_64 1:0-3.11.gitdd0daef.el7 will be erased
---> Package oci-systemd-hook.x86_64 1:0.1.7-2.git2788078.el7 will be erased
---> Package policycoreutils.x86_64 0:2.5-8.el7 will be a downgrade
---> Package policycoreutils.x86_64 0:2.5-11.el7_3 will be erased
---> Package policycoreutils-python.x86_64 0:2.5-11.el7_3 will be erased
---> Package python-IPy.noarch 0:0.75-6.el7 will be erased
---> Package setools-libs.x86_64 0:3.3.8-1.1.el7 will be erased
---> Package skopeo-containers.x86_64 1:0.1.19-1.el7 will be erased
---> Package yajl.x86_64 0:2.0.4-4.el7 will be erased
--> Finished Dependency Resolution

Dependencies Resolved

================================================================================
 Package                Arch   Version                           Repository
                                                                           Size
================================================================================
Removing:
 audit-libs-python      x86_64 2.6.5-3.el7_3.1                   @updates 302 k
 checkpolicy            x86_64 2.5-4.el7                         @base    1.2 M
 container-selinux      noarch 2:2.12-2.gite7096ce.el7           @extras   32 k
 device-mapper-event    x86_64 7:1.02.135-1.el7_3.4              @updates  45 k
 device-mapper-event-libs
                        x86_64 7:1.02.135-1.el7_3.4              @updates  53 k
 device-mapper-persistent-data
                        x86_64 0.6.3-1.el7                       @base    1.2 M
 docker                 x86_64 2:1.12.6-28.git1398f24.el7.centos @extras   50 M
 docker-client          x86_64 2:1.12.6-28.git1398f24.el7.centos @extras   11 M
 docker-common          x86_64 2:1.12.6-28.git1398f24.el7.centos @extras  5.2 k
 libcgroup              x86_64 0.41-11.el7                       @base    130 k
 libseccomp             x86_64 2.3.1-2.el7                       @base    297 k
 libsemanage-python     x86_64 2.5-5.1.el7_3                     @updates 377 k
 lvm2                   x86_64 7:2.02.166-1.el7_3.4              @updates 2.4 M
 lvm2-libs              x86_64 7:2.02.166-1.el7_3.4              @updates 3.1 M
 oci-register-machine   x86_64 1:0-3.11.gitdd0daef.el7           @extras  3.1 M
 oci-systemd-hook       x86_64 1:0.1.7-2.git2788078.el7          @extras   65 k
 policycoreutils-python x86_64 2.5-11.el7_3                      @updates 1.2 M
 python-IPy             noarch 0.75-6.el7                        @base    119 k
 setools-libs           x86_64 3.3.8-1.1.el7                     @base    1.8 M
 skopeo-containers      x86_64 1:0.1.19-1.el7                    @extras  1.1 k
 yajl                   x86_64 2.0.4-4.el7                       @base    114 k
Downgrading:
 audit                  x86_64 2.6.5-3.el7                       base     233 k
 audit-libs             x86_64 2.6.5-3.el7                       base      85 k
 device-mapper          x86_64 7:1.02.135-1.el7                  base     269 k
 device-mapper-libs     x86_64 7:1.02.135-1.el7                  base     333 k
 libsemanage            x86_64 2.5-4.el7                         base     144 k
 policycoreutils        x86_64 2.5-8.el7                         base     841 k

Transaction Summary
================================================================================
Remove     21 Packages
Downgrade   6 Packages

Total download size: 1.9 M
Is this ok [y/d/N]: y
Downloading packages:
(1/6): audit-libs-2.6.5-3.el7.x86_64.rpm                   |  85 kB   00:00     
(2/6): audit-2.6.5-3.el7.x86_64.rpm                        | 233 kB   00:00     
(3/6): device-mapper-1.02.135-1.el7.x86_64.rpm             | 269 kB   00:00     
(4/6): device-mapper-libs-1.02.135-1.el7.x86_64.rpm        | 333 kB   00:00     
(5/6): libsemanage-2.5-4.el7.x86_64.rpm                    | 144 kB   00:00     
(6/6): policycoreutils-2.5-8.el7.x86_64.rpm                | 841 kB   00:00     
--------------------------------------------------------------------------------
Total                                              1.8 MB/s | 1.9 MB  00:01     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : audit-libs-2.6.5-3.el7.x86_64                               1/33 
  Installing : libsemanage-2.5-4.el7.x86_64                                2/33 
  Installing : 7:device-mapper-libs-1.02.135-1.el7.x86_64                  3/33 
  Installing : 7:device-mapper-1.02.135-1.el7.x86_64                       4/33 
  Installing : policycoreutils-2.5-8.el7.x86_64                            5/33 
  Installing : audit-2.6.5-3.el7.x86_64                                    6/33 
  Erasing    : 2:docker-1.12.6-28.git1398f24.el7.centos.x86_64             7/33 
  Erasing    : 7:lvm2-2.02.166-1.el7_3.4.x86_64                            8/33 
  Erasing    : 2:container-selinux-2.12-2.gite7096ce.el7.noarch            9/33 
  Erasing    : policycoreutils-python-2.5-11.el7_3.x86_64                 10/33 
  Erasing    : 7:lvm2-libs-2.02.166-1.el7_3.4.x86_64                      11/33 
  Erasing    : 7:device-mapper-event-1.02.135-1.el7_3.4.x86_64            12/33 
  Cleanup    : policycoreutils-2.5-11.el7_3.x86_64                        13/33 
  Erasing    : 7:device-mapper-event-libs-1.02.135-1.el7_3.4.x86_64       14/33 
  Cleanup    : 7:device-mapper-libs-1.02.135-1.el7_3.4.x86_64             15/33 
  Cleanup    : 7:device-mapper-1.02.135-1.el7_3.4.x86_64                  16/33 
  Erasing    : audit-libs-python-2.6.5-3.el7_3.1.x86_64                   17/33 
  Erasing    : libsemanage-python-2.5-5.1.el7_3.x86_64                    18/33 
  Cleanup    : libsemanage-2.5-5.1.el7_3.x86_64                           19/33 
  Erasing    : 2:docker-client-1.12.6-28.git1398f24.el7.centos.x86_64     20/33 
  Erasing    : 1:oci-systemd-hook-0.1.7-2.git2788078.el7.x86_64           21/33 
  Cleanup    : audit-2.6.5-3.el7_3.1.x86_64                               22/33 
  Erasing    : 2:docker-common-1.12.6-28.git1398f24.el7.centos.x86_64     23/33 
  Erasing    : python-IPy-0.75-6.el7.noarch                               24/33 
  Erasing    : 1:skopeo-containers-0.1.19-1.el7.x86_64                    25/33 
  Cleanup    : audit-libs-2.6.5-3.el7_3.1.x86_64                          26/33 
  Erasing    : yajl-2.0.4-4.el7.x86_64                                    27/33 
  Erasing    : checkpolicy-2.5-4.el7.x86_64                               28/33 
  Erasing    : setools-libs-3.3.8-1.1.el7.x86_64                          29/33 
  Erasing    : libcgroup-0.41-11.el7.x86_64                               30/33 
  Erasing    : device-mapper-persistent-data-0.6.3-1.el7.x86_64           31/33 
  Erasing    : libseccomp-2.3.1-2.el7.x86_64                              32/33 
  Erasing    : 1:oci-register-machine-0-3.11.gitdd0daef.el7.x86_64        33/33 
  Verifying  : policycoreutils-2.5-8.el7.x86_64                            1/33 
  Verifying  : audit-libs-2.6.5-3.el7.x86_64                               2/33 
  Verifying  : audit-2.6.5-3.el7.x86_64                                    3/33 
  Verifying  : 7:device-mapper-1.02.135-1.el7.x86_64                       4/33 
  Verifying  : 7:device-mapper-libs-1.02.135-1.el7.x86_64                  5/33 
  Verifying  : libsemanage-2.5-4.el7.x86_64                                6/33 
  Verifying  : libseccomp-2.3.1-2.el7.x86_64                               7/33 
  Verifying  : 1:skopeo-containers-0.1.19-1.el7.x86_64                     8/33 
  Verifying  : policycoreutils-python-2.5-11.el7_3.x86_64                  9/33 
  Verifying  : 1:oci-register-machine-0-3.11.gitdd0daef.el7.x86_64        10/33 
  Verifying  : 7:device-mapper-1.02.135-1.el7_3.4.x86_64                  11/33 
  Verifying  : audit-2.6.5-3.el7_3.1.x86_64                               12/33 
  Verifying  : policycoreutils-2.5-11.el7_3.x86_64                        13/33 
  Verifying  : 2:docker-1.12.6-28.git1398f24.el7.centos.x86_64            14/33 
  Verifying  : device-mapper-persistent-data-0.6.3-1.el7.x86_64           15/33 
  Verifying  : 7:device-mapper-event-libs-1.02.135-1.el7_3.4.x86_64       16/33 
  Verifying  : 7:lvm2-2.02.166-1.el7_3.4.x86_64                           17/33 
  Verifying  : python-IPy-0.75-6.el7.noarch                               18/33 
  Verifying  : 7:device-mapper-libs-1.02.135-1.el7_3.4.x86_64             19/33 
  Verifying  : 2:docker-common-1.12.6-28.git1398f24.el7.centos.x86_64     20/33 
  Verifying  : 7:lvm2-libs-2.02.166-1.el7_3.4.x86_64                      21/33 
  Verifying  : libcgroup-0.41-11.el7.x86_64                               22/33 
  Verifying  : libsemanage-2.5-5.1.el7_3.x86_64                           23/33 
  Verifying  : 2:container-selinux-2.12-2.gite7096ce.el7.noarch           24/33 
  Verifying  : 7:device-mapper-event-1.02.135-1.el7_3.4.x86_64            25/33 
  Verifying  : yajl-2.0.4-4.el7.x86_64                                    26/33 
  Verifying  : 1:oci-systemd-hook-0.1.7-2.git2788078.el7.x86_64           27/33 
  Verifying  : audit-libs-python-2.6.5-3.el7_3.1.x86_64                   28/33 
  Verifying  : libsemanage-python-2.5-5.1.el7_3.x86_64                    29/33 
  Verifying  : 2:docker-client-1.12.6-28.git1398f24.el7.centos.x86_64     30/33 
  Verifying  : audit-libs-2.6.5-3.el7_3.1.x86_64                          31/33 
  Verifying  : setools-libs-3.3.8-1.1.el7.x86_64                          32/33 
  Verifying  : checkpolicy-2.5-4.el7.x86_64                               33/33 

Removed:
  audit.x86_64 0:2.6.5-3.el7_3.1                                                
  audit-libs.x86_64 0:2.6.5-3.el7_3.1                                           
  audit-libs-python.x86_64 0:2.6.5-3.el7_3.1                                    
  checkpolicy.x86_64 0:2.5-4.el7                                                
  container-selinux.noarch 2:2.12-2.gite7096ce.el7                              
  device-mapper.x86_64 7:1.02.135-1.el7_3.4                                     
  device-mapper-event.x86_64 7:1.02.135-1.el7_3.4                               
  device-mapper-event-libs.x86_64 7:1.02.135-1.el7_3.4                          
  device-mapper-libs.x86_64 7:1.02.135-1.el7_3.4                                
  device-mapper-persistent-data.x86_64 0:0.6.3-1.el7                            
  docker.x86_64 2:1.12.6-28.git1398f24.el7.centos                               
  docker-client.x86_64 2:1.12.6-28.git1398f24.el7.centos                        
  docker-common.x86_64 2:1.12.6-28.git1398f24.el7.centos                        
  libcgroup.x86_64 0:0.41-11.el7                                                
  libseccomp.x86_64 0:2.3.1-2.el7                                               
  libsemanage.x86_64 0:2.5-5.1.el7_3                                            
  libsemanage-python.x86_64 0:2.5-5.1.el7_3                                     
  lvm2.x86_64 7:2.02.166-1.el7_3.4                                              
  lvm2-libs.x86_64 7:2.02.166-1.el7_3.4                                         
  oci-register-machine.x86_64 1:0-3.11.gitdd0daef.el7                           
  oci-systemd-hook.x86_64 1:0.1.7-2.git2788078.el7                              
  policycoreutils.x86_64 0:2.5-11.el7_3                                         
  policycoreutils-python.x86_64 0:2.5-11.el7_3                                  
  python-IPy.noarch 0:0.75-6.el7                                                
  setools-libs.x86_64 0:3.3.8-1.1.el7                                           
  skopeo-containers.x86_64 1:0.1.19-1.el7                                       
  yajl.x86_64 0:2.0.4-4.el7                                                     

Installed:
  audit.x86_64 0:2.6.5-3.el7                                                    
  audit-libs.x86_64 0:2.6.5-3.el7                                               
  device-mapper.x86_64 7:1.02.135-1.el7                                         
  device-mapper-libs.x86_64 7:1.02.135-1.el7                                    
  libsemanage.x86_64 0:2.5-4.el7                                                
  policycoreutils.x86_64 0:2.5-8.el7                                            

Complete!