Erase multiple packages using rpm or yum

jerry picture jerry · Aug 17, 2012 · Viewed 37.2k times · Source

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.

Answer

Acumenus picture Acumenus · Mar 10, 2014

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*'