Erase multiple packages using rpm or yum

后端 未结 5 984
故里飘歌
故里飘歌 2021-02-01 23:17

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         


        
相关标签:
5条回答
  • 2021-02-01 23:28

    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*'
    
    0 讨论(0)
  • 2021-02-01 23:41

    to list:

    rpm -qa | grep 'php'
    

    to remove instaled listed and filtrated:

    rpm -e $(rpm -qa |grep 'php')
    
    0 讨论(0)
  • 2021-02-01 23:43

    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.

    0 讨论(0)
  • 2021-02-01 23:49

    Another option is to use the output of rpm -qa | grep ... in the rpm --erase command directly:

    rpm --erase `rpm -qa | grep php`
    

    Maybe not for the php case you're citing, but the xargs approach might possibly run into issues if it decides to split the list into several invocations of rpm -e and the first list contains packages that are dependencies of packages in subsequent lists. Of course, if you're removing that many packages all at once, you might have other things that you need to consider...

    0 讨论(0)
  • 2021-02-01 23:52

    I had this today. Using --justdb and --noscripts rpm parameters wasn't sufficient without the --allmatches, and that's it.

    [root@localhost ~]# rpm -ev --allmatches --justdb <the-package-name>
    

    https://mcvictech.blogspot.com/2011/10/rpm-error-specifies-multiple-packages.html

    0 讨论(0)
提交回复
热议问题