Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Erase multiple packages using rpm or yum

Tags:

unix

rpm

yum

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.

like image 226
jerry Avatar asked Aug 17 '12 12:08

jerry


People also ask

Should I use yum or rpm?

RPM is powerful when you have the required . rpm packages and the dependencies manually figured out or if you need to query the package information database. Otherwise, it is better to use YUM in day-to-day usage because it keeps the system updated and clean.

What is advantage of yum over rpm?

The advantage of yum over the rpm command is it deals with all dependencies for you, prompting you with the required dependencies and the total size of the operation. If you agree, all necessary dependencies will be installed, in addition to your specified package(s).

Does yum remove dependencies?

From now, every time you remove a packages, YUM goes through each package's dependencies and remove them if they are no longer needed by any other package.


2 Answers

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*'
like image 70
Asclepius Avatar answered Sep 20 '22 16:09

Asclepius


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.

like image 30
thkala Avatar answered Sep 19 '22 16:09

thkala