Jeff Sheffield
Jeff Sheffield

Reputation: 6316

How do I uninstall all rpms installed today with yum?

I am very familiar with

rpm -qa --last

and have found it to be very handy on certain occasions. However on this occasion I accidentally got a bit overzealous and installed a large yum group.

yum groupinstall "Development tools"

Is there an easy way to uninstall everything I just installed? Seems to me there should be some way to combine rpm query and rpm erase. i.e. piping the output from a query command into the remove command.

Update: based on user @rickhg12hs feedback

It was pointed out that I can see the transaction id with yum history which I did not know about. Here is what that looks like:

$ yum history

Loaded plugins: fastestmirror, security
ID | Login user               | Date and time    | Action(s)      | Altered
----------------------------------------------------------------------------
69 |  <jds>                   | 2015-05-11 01:31 | Install        |    1   
68 |  <jds>                   | 2015-05-11 01:31 | Install        |    1   
67 |  <jds>                   | 2015-05-11 01:10 | I, U           |  210   
66 |  <jds>                   | 2015-05-05 12:41 | Install        |    1   
65 |  <jds>                   | 2015-04-30 17:57 | Install        |    2   
64 |  <ansible>               | 2015-04-30 10:11 | Install        |    1   
63 |  <ansible>               | 2015-04-30 10:11 | Install        |    1   
62 |  <ansible>               | 2015-04-30 10:11 | Install        |    1 EE
61 |  <ansible>               | 2015-04-30 10:11 | Install        |    1   
60 |  <ansible>               | 2015-04-30 10:11 | Install        |    1   
59 |  <ansible>               | 2015-04-30 09:58 | Install        |   19 P<
58 |  <ansible>               | 2015-04-29 18:28 | Install        |    1 > 
57 |  <ansible>               | 2015-04-29 18:28 | Install        |    1   
56 |  <ansible>               | 2015-04-29 18:28 | Install        |    9   
55 |  <ansible>               | 2015-04-29 18:28 | Install        |    3   
54 |  <ansible>               | 2015-04-29 18:28 | Install        |    1   
53 |  <ansible>               | 2015-04-29 18:27 | I, U           |    5   
52 |  <ansible>               | 2015-04-29 18:27 | I, U           |    4   
51 |  <ansible>               | 2015-04-29 18:27 | Install        |    1   
50 |  <ansible>               | 2015-04-29 18:27 | Install        |    1   

and tada: There it is, a transaction id.

I want to uninstall from transaction id 67. So now that I am a bit wiser I have a new question.

So how can I use the yum or rpm command to uninstall a transaction?

Note: it was also pointed out to me that I can do a

$ yum history info 67 |less

Loaded plugins: fastestmirror, security
Transaction ID : 67
Begin time     : Mon May 11 01:10:09 2015
Begin rpmdb    : 1012:bb05598315dcb21812b038a356fa06333d277cde
End time       :            01:13:25 2015 (196 seconds)
End rpmdb      : 1174:cb7855e82c7bff545319c38b01a72a48f3ada1ab
User           :  <jds>
Return-Code    : Success
Command Line   : groupinstall Additional Development
Transaction performed with:
   Installed     rpm-4.8.0-38.el6_6.x86_64                     @updates
   Installed     yum-3.2.29-60.el6.centos.noarch               @anaconda-CentOS-201410241409.x86_64/6.6
   Installed     yum-plugin-fastestmirror-1.1.30-30.el6.noarch @anaconda-CentOS-201410241409.x86_64/6.6
Packages Altered:
   Dep-Install GConf2-2.28.0-6.el6.x86_64                                @base
   Install     GConf2-devel-2.28.0-6.el6.x86_64                          @base
   Dep-Install ORBit2-2.14.17-5.el6.x86_64                               @base
   ... snip ...

I think this could prove quite helpful under certain circumstances.

Upvotes: 4

Views: 4500

Answers (3)

M.N.
M.N.

Reputation: 121

Yum has provision for you to undo your command i.e. yum history undo #blah

In your case, to remove all packages you installed today you can run :

yum history undo 69
yum history undo 68
yum history undo 67

Upvotes: 1

Jeff Johnson
Jeff Johnson

Reputation: 2390

All packages installed in a single transaction have an identical RPMTAG_INSTALLTID tag value.

Use

rpm -qa --qf '[%{name}\t%{installtid:date}\n]'

to find all packages that were installed as part of the yum group install.

Upvotes: 1

Thomas Dickey
Thomas Dickey

Reputation: 54603

If you uninstall packages, then you run the risk of removing things that were already there, but happened to be upgraded. As a rule, you should use yum (or equivalent) for managing packages, which allows you to downgrade a package. This would remove new packages, and downgrade existing ones. See for example How to safely downgrade or remove glibc with yum and rpm

Selecting the names of packages to downgrade can be done using the output of rpm -qa, formatted to allow simple selection of the given date. For instance (see CentOS: List the installed RPMs by date of installation/update?), you can list packages in the reverse-order of their install date using

rpm -qa --last

As a more elaborate approach, you can use the --queryformat option with the :date option to format the date exactly as you want (it uses strftime).

In either case, you can make a script to extract the package names from the output of rpm, and use those packages with yum (or even rpm) to manipulate as needed.

When doing a downgrade, there is one odd thing to keep in mind: that revises the install-date for packages to be the current date rather than a complete undo, by using the previous date.

Upvotes: 2

Related Questions