Erase multiple packages using rpm or yum
Asked Answered
F

5

19

I was given access to a server with 50+ php rpms installed. I'm trying to remove them all.

Basically, I'm trying to combine these two commands:

rpm -qa | grep 'php'

and

rpm --erase

I know a little about pipes and redirection, but I don't see how to use them for this purpose. Please help.

Farthest answered 17/8, 2012 at 12:10 Comment(0)
E
40

Using yum

List and remove the indicated packages and all their dependencies, but with a y/N confirmation:

yum remove 'php*'

To bypass the confirmation, replace yum with yum -y.

Using rpm

This section builds upon the answers by twalburg and Ricardo.

List which RPMs are installed:

rpm -qa 'php*'
rpm -qa | grep '^php'  # Alternative listing.

List which RPMs which will be erased, without actually erasing them:

rpm -e --test -vv $(rpm -qa 'php*') 2>&1 | grep '^D:     erase:'

On Amazon Linux, you may need to use grep '^D: ========== ---' instead.

If the relevant RPMs are not listed by the command above, investigate errors:

rpm -e --test -vv $(rpm -qa 'php*')

Erase these RPMs:

rpm -e $(rpm -qa 'php*')

Confirm the erasure:

rpm -qa 'php*'
Erda answered 10/3, 2014 at 22:46 Comment(1)
The grep command doesn't pick up anything on my Amazon Linux instance, I think it should be looking for '^D: ========== ---' instead. Also (because this is non-obvious), in the case of multiple wildcards (e.g., LibreOffice), the query command would look like rpm -qa 'libreoffice*' 'libobasis*'.Container
S
10

The usual tool for this job is xargs:

rpm -qa | grep 'php' | xargs rpm -e

This will call rpm -e with all packages named in the standard input of xargs as arguments.

Sunrise answered 17/8, 2012 at 15:15 Comment(1)
This approach will often simply fail due to dependencies.Erda
H
1

Another option is to use the output of rpm -qa | grep ... in the rpm --erase command directly:

rpm --erase `rpm -qa | grep php`

Maybe not for the php case you're citing, but the xargs approach might possibly run into issues if it decides to split the list into several invocations of rpm -e and the first list contains packages that are dependencies of packages in subsequent lists. Of course, if you're removing that many packages all at once, you might have other things that you need to consider...

Homs answered 17/8, 2012 at 16:2 Comment(0)
A
0

to list:

rpm -qa | grep 'php'

to remove instaled listed and filtrated:

rpm -e $(rpm -qa |grep 'php')
Antimere answered 27/5, 2013 at 8:23 Comment(0)
F
0

I had this today. Using --justdb and --noscripts rpm parameters wasn't sufficient without the --allmatches, and that's it.

[root@localhost ~]# rpm -ev --allmatches --justdb <the-package-name>

https://mcvictech.blogspot.com/2011/10/rpm-error-specifies-multiple-packages.html

Freehanded answered 5/4, 2020 at 20:11 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.