[daily][CentOS][yum] 刪除包的同時一同清理掉安裝時一起裝進來的依賴包


說起來有點繞口,這個需求是這樣的。

就是我yum裝A包的時候,同時安裝了A的依賴包a1,a2,a3。

當我們使用yum remove A卸載A包的是,a1,a2,a3包並不會一同被卸載掉。如果他們沒有用了,即除了A並沒有其他包依賴他們的話,他們也應該一同被卸載掉。

在arch里,我們有pacman -Rsun等復雜的命令搞定這件事(pacman這一套我確實也沒用學的很明白,有時間還有再好好學一學。

並且我們還有,pacman -Qdt。pacman -Qet 。pactree,等命令來清澈的管理所有包和他們直接的依賴樹,以及誰是孤立的,誰是曾經被依賴如今可以刪的。

 

所以,在CentOS里,yum該怎么做才能達到這些目的呢?我當前的要求很簡單,就是remove的時候,把依賴一起帶走就可以了。

分別 man yum 和man yum.conf 之后發現是可以的。

方法一:使用 yum autoremove

       autoremove

              With one or more arguments this command works like running the "remove" command with the clean_requirements_on_remove turned on. However you can also
              specify no arguments, at which point it tries to remove any packages that weren't installed explicitly by the user and which aren't required by  any‐
              thing (so called leaf packages).

              Because  autoremove  does  a  lot  of  work  to make it as easy as possible to use, there are also a few specific autoremove commands "autoremove-n",
              "autoremove-na" and "autoremove-nevra". These only work on package names, and do not process wildcards etc.

方法二:在yum.conf中設置參數 clean_requirements_on_remove 然后使用 yum remove xxx

              clean_requirements_on_remove When removing packages (by removal, update or obsoletion) go through each package's dependencies. If any of them are  no
              longer required by any other package then also mark them to be removed.  Boolean (1, 0, True, False, yes, no) Defaults to False

 

好吧,說的這么費勁其實答案就是 aoturemove

[root@dpdk ~]# rpm -qa |grep dpdk
dpdk-2.2.0-3.el7.x86_64
dpdk-devel-2.2.0-3.el7.x86_64
[root@dpdk ~]# yum autoremove dpdk-devel
Loaded plugins: fastestmirror
Resolving Dependencies
--> Running transaction check
---> Package dpdk-devel.x86_64 0:2.2.0-3.el7 will be erased
--> Finished Dependency Resolution
--> Finding unneeded leftover dependencies
---> Marking dpdk to be removed - no longer needed by dpdk-devel
Found and removing 1 unneeded dependencies
--> Running transaction check
---> Package dpdk.x86_64 0:2.2.0-3.el7 will be erased
--> Finished Dependency Resolution

Dependencies Resolved

========================================================================================================================================================================
 Package                                  Arch                                 Version                                      Repository                             Size
========================================================================================================================================================================
Removing:
 dpdk-devel                               x86_64                               2.2.0-3.el7                                  @extras                               1.4 M
Removing for dependencies:
 dpdk                                     x86_64                               2.2.0-3.el7                                  @extras                               2.7 M

Transaction Summary
========================================================================================================================================================================
Remove  1 Package (+1 Dependent package)

Installed size: 4.1 M
Is this ok [y/N]: y
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Erasing    : dpdk-devel-2.2.0-3.el7.x86_64                                                                                                                        1/2 
  Erasing    : dpdk-2.2.0-3.el7.x86_64                                                                                                                              2/2 
  Verifying  : dpdk-devel-2.2.0-3.el7.x86_64                                                                                                                        1/2 
  Verifying  : dpdk-2.2.0-3.el7.x86_64                                                                                                                              2/2 

Removed:
  dpdk-devel.x86_64 0:2.2.0-3.el7                                                                                                                                       

Dependency Removed:
  dpdk.x86_64 0:2.2.0-3.el7                                                                                                                                             

Complete!
[root@dpdk ~]# rpm -qa |grep dpdk
[root@dpdk ~]# 

 

最后,親測可用,當當當當!:)

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM