1

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

Buttle Butkus
  • 1,719
  • 8
  • 32
  • 45

2 Answers2

1

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,.

voretaq7
  • 79,345
  • 17
  • 128
  • 213
frankcui24
  • 46
  • 6
  • 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 05: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
0
yum remove php\*

I had previously tried

yum remove php*

which obviously didn't work

EEAA
  • 108,414
  • 18
  • 172
  • 242
Buttle Butkus
  • 1,719
  • 8
  • 32
  • 45
  • 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