I need to upgrade php from 5.3 to 5.4. I've installed it with rpm. I want clean install: delete all 5.3 packages, and install all necessary 5.4. Here is the command to see all installed packages:

rpm -qa |grep php

It prints out a list of packages, and I want to remove all them with:

rpm -e *pakage.name*

Can I iterate over all matches in grep results and use each match in:

rpm -e *grep.match*
  • 1
    rpm -qa does not need grep to be invoked. It accepts globbing as in rpm qa *php*. Also use yum instead as it will remove / reinstall necessary libraries – Valentin Bajrami Apr 14 '14 at 19:39

Try this:

rpm -qa | grep php | xargs rpm -e

You generally don't want to remove packages like this in pieces since there's typically dependencies that you're skipping over. Better to do this removal all at once like so:

$ rpm -e $(rpm -aq | grep php)

Better still I would encourage you to use yum to do this vs. RPM.

$ yum remove $(rpm -aq | grep php)

Even better then these would be to figure out a pattern that matches all the PHP packages and tell YUM to remove based on the pattern . Yes YUM is aware of regular expressions.

$ yum remove 'php*'

You'll need to make sure that your entire list of packages will fit on the command line but doing this using xargs or individually is wrought with problems, if you tell rpm to remove 1/2 of the PHP related packages in one command, followed by another rpm command with the rest.

  • Thaks for explanation! Will try your advice next time. I've alredy removed all and have php5.4 installed. – Anatoliy Gusarov Apr 14 '14 at 19:57

Try this script:

for p in $(rpm -qa |grep php) ; do rpm -e ${p} ; done
  • @terdon Thanks for the hint, I should really get used replacing those backticks with the $() notation ... – phlogratos Apr 14 '14 at 19:44
( IFS='
' ; printf 'rpm -e "%s"\n' $(rpm -qa |grep php) |
    . /dev/stdin )

There you go.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.