Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have a newly installed CentOS 5.7 machine and mistakenly installed PHP 5.1 when I needed 5.2+.

Now I cannot seem to install PHP 5.3 (using "yum install php53") until I remove PHP 5.1.

I found this tutorial, which has you type:

yum remove package1 package2 package...

But it takes so long that way.

Is there a faster way, something like:

rpm -qa | grep php -exec yum remove {} \;

?

Thank you

share|improve this question

2 Answers 2

Using the link you provided, you can first find what php-related packages you have installed by using :

yum list installed | grep php | cut -d' ' -f1 | tr "\n" " "

you can use this command output and feed it to yum remove, the simplest example is as follows

yum remove `echo bind`

the backtick symbol (`) is located to the left of the "1" key on standard US keyboards.
and echo bind should be replaced with the yum list command.

so the command should be:

yum remove `yum list installed | grep php | cut -d' ' -f1 | tr "\n" " "`

I'm on ubuntu so cannot test this very well, but hope this works on your box,.

share|improve this answer
    
Very well done! I entered your code and it works perfectly. I'm not sure if it's better than "yum remove php-*" though. What do you think? Also, your explanation is really good but I was confused for a second by your comment about ` so I'm going to propose an edit. –  Buttle Butkus Jan 28 '12 at 5:07
    
Thanks for the editing. I don't see any difference between the two since we are both finding packages that match the pattern. And to further automate this process, the -y option could be used which skips the confirmation process. –  frankcui24 Jan 28 '12 at 14:16
yum remove php\*

I had previously tried

yum remove php*

which obviously didn't work

share|improve this answer
1  
With the command "yum remove php*", you may have had files in the current working directory that matches the glob (since you said you're working on package upgrades). In that case, shell expansion would have resulting in the actual command being "yum remove php-blah-blah-blah.rpm" or whatever was in that directory, which would have failed because there'd be no such installed package. The "\" would have escaped the "*" and stopped the shell expansion. –  cjc Jan 28 '12 at 13:25

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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