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.
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.
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).
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.
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
.
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*'
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With