Answers:
您想要的rpm选项是:
rpm -q --whatrequires sqlite
编辑:添加-根据讨论在其他答案/评论中安装
编辑:删除-安装,因为它是rpm的无效选项
--installed
是的选项,repoquery
但对无效rpm
。
repoquery -q --installed --whatrequires sqlite
rpm -q --whatrequires sqlite
仅报告对程序包名称的依赖性。
相反,其repoquery
作用如下(来自联机帮助页):
--alldeps
When used with --whatrequires, look for non-explicit dependencies in addition to explicit ones (e.g. files and Provides in addition to package names).
This is the default.
让我们拿包libdb
。
# rpm -q --whatrequires libdb
no package requires libdb
没有任何包依赖libdb
,因此我们应该能够顺利删除它。然而...
# yum remove -y libdb
Loaded plugins: fastestmirror
Resolving Dependencies
--> Running transaction check
---> Package libdb.x86_64 0:5.3.21-19.el7 will be erased
--> Processing Dependency: libdb(x86-64) = 5.3.21-19.el7 for package: libdb-utils-5.3.21-19.el7.x86_64
--> Processing Dependency: libdb-5.3.so()(64bit) for package: pam-1.1.8-12.el7_1.1.x86_64
--> Processing Dependency: libdb-5.3.so()(64bit) for package: rpm-4.11.3-17.el7.x86_64
--> Processing Dependency: libdb-5.3.so()(64bit) for package: rpm-libs-4.11.3-17.el7.x86_64
--> Processing Dependency: libdb-5.3.so()(64bit) for package: libdb-utils-5.3.21-19.el7.x86_64
--> Processing Dependency: libdb-5.3.so()(64bit) for package: cyrus-sasl-lib-2.1.26-20.el7_2.x86_64
--> Processing Dependency: libdb-5.3.so()(64bit) for package: rpm-python-4.11.3-17.el7.x86_64
--> Processing Dependency: libdb-5.3.so()(64bit) for package: python-libs-2.7.5-39.el7_2.x86_64
--> Processing Dependency: libdb-5.3.so()(64bit) for package: rpm-devel-4.11.3-17.el7.x86_64
--> Processing Dependency: libdb-5.3.so()(64bit) for package: 2:postfix-2.10.1-6.el7.x86_64
--> Processing Dependency: libdb-5.3.so()(64bit) for package: rpm-build-libs-4.11.3-17.el7.x86_64
--> Processing Dependency: libdb-5.3.so()(64bit) for package: iproute-3.10.0-54.el7_2.1.x86_64
--> Running transaction check
. . .
. . .
. . .
Error: Trying to remove "systemd", which is protected
Error: Trying to remove "yum", which is protected
如您所见,其他一些软件包并不直接取决于该软件包,而是取决于libdb-5.3.so()(64bit)
它提供的文件。
最后,这是取决于的实际包列表libdb
:
# repoquery -q --installed --whatrequires libdb
cyrus-sasl-lib-0:2.1.26-20.el7_2.x86_64
iproute-0:3.10.0-54.el7_2.1.x86_64
libdb-utils-0:5.3.21-19.el7.x86_64
pam-0:1.1.8-12.el7_1.1.x86_64
postfix-2:2.10.1-6.el7.x86_64
python-libs-0:2.7.5-39.el7_2.x86_64
rpm-0:4.11.3-17.el7.x86_64
rpm-build-libs-0:4.11.3-17.el7.x86_64
rpm-devel-0:4.11.3-17.el7.x86_64
rpm-libs-0:4.11.3-17.el7.x86_64
rpm-python-0:4.11.3-17.el7.x86_64
正如Wes Hardaker所说,一种好的内置方法是使用rpm -q --whatrequires <package>
。事实是,rpm
运行在功能的解决依赖,不只是简单地封装,例如dpkg
可以在Debian / Ubuntu的家庭Linux发行版一样。正如其他人指出的那样,简单地做rpm -q --whatrequires sqlite
并不能说明全部内容,因此为什么有人建议使用repoquery
。repoquery
,但是默认情况下未在RHEL / CentOS 7最低版中安装(也许也可以在台式机上安装),因此可能并非所有人都可以使用。
用户可以rpm -q --provides <pkgname>
查看软件包提供的所有功能,然后使用rpm -q --whatrequires <capability>
查看哪些已安装的软件包需要该功能。可以使用BASH单线简洁地查询此信息(此处分成两行以表示长度):
capabilities=($(rpm -q --provides sqlite | awk -F= '{print $1}'));
for c in "${capabilities[@]}"; do rpm -q --whatrequires "$c"; done
这仅使用rpm
自身内置的选项,因此不需要安装任何其他软件包(例如,yum-utils
在包含的软件包CentOS 7中repoquery
)。
repoquery
可用于为需要特定软件包的所有软件包生成类似结构的漂亮树,例如:repoquery --pkgnarrow=installed --tree-whatrequires sqlite