![如何对已安装的rpm包进行拓扑排序?](https://linux22.com/image/154898/%E5%A6%82%E4%BD%95%E5%AF%B9%E5%B7%B2%E5%AE%89%E8%A3%85%E7%9A%84rpm%E5%8C%85%E8%BF%9B%E8%A1%8C%E6%8B%93%E6%89%91%E6%8E%92%E5%BA%8F%EF%BC%9F.png)
我想根据依赖关系对 Fedora 上所有已安装的 rpm 软件包进行拓扑排序,其中最需要的软件包位于顶部(例如 glibc),而最少需要的软件包位于底部。我可以列出所有已安装的软件包rpm -qa
,但它们似乎没有按拓扑排序。
我的目标是检查已安装的软件包,找到我不再需要的软件包并卸载它们。
答案1
rpmgraph(8) - Linux man page
Name
rpmgraph - Display RPM Package Dependency Graph
Synopsis
rpmgraph PACKAGE_FILE ...
Description
rpmgraph uses PACKAGE_FILE arguments to generate a package dependency graph. Each
PACKAGE_FILE argument is read and added to an rpm transaction set. The elements
of the transaction set
are partially ordered using a topological sort.
The partially ordered elements are then printed to standard output.
Nodes in the dependency graph are package names, and edges in the directed graph
point to the parent of each node. The parent node is defined as the last
predecessor of a package when partially ordered using the package dependencies as
a relation. That means that the parent of a given package is the package's last
prerequisite.
The output is in dot(1) directed graph format, and can be displayed or printed
using the dotty graph editor from the graphviz package. There are no rpmgraph
specific options, only common rpm options. See the rpmgraph usage message for
what is currently implemented.
[1]: https://linux.die.net/man/8/rpmgraph
安装:
使用你的包管理器:
dnf install rpm-devel
要安装wget
在 中CentOS
,请在终端窗口中输入以下内容:
sudo yum install wget
要安装wget
在 中Fedora
,请输入以下内容:
sudo dnf install wget
现在,您可以使用 wget 命令下载所需的 .rpm 文件。输入以下内容:
wget http://some_website/sample_file.rpm
系统应该访问该网站并将文件下载到您当前的工作目录。
使用 RPM 命令安装 RPM 文件
Fedora
要在Linux中安装 .rpm 软件包CentOS
,请输入以下内容:
sudo rpm –i sample_file.rpm
–i 开关告诉包管理器您要安装该文件。
有关 RPM 安装程序的更多信息,请参阅转速文档。
使用 Yum 安装 RPM 文件
或者,您可以使用yum
包管理器来安装.rpm
文件。
输入以下内容:
sudo yum localinstall sample_file.rpm
该localinstall
选项指示 yum 查看当前工作目录中的安装文件。
https://superuser.com/questions/483307/how-do-i-know-dependent-rpms-of-aa-package
https://phoenixnap.com/kb/how-to-install-rpm-file-centos-linux
https://linux.die.net/man/8/rpm
编辑:
我无法开始rpmgraph
工作,我尝试了三种不同版本的PACKAGE_FILE
包列表语法,但它只是给出错误,如果您知道如何使用这个程序,请提供答案或编辑我的。测试于Fedora 28
.如何列出所有已安装的扩展名为 .rpm 的软件包。 Fedora、Centos、红帽
# rpmgraph INSTALLED_PACKAGES
(null): read manifest failed:
答案2
经过一番搜索后,似乎包rpmdep
中的工具rpmorphan
最接近我想要的。要查看最需要的已安装软件包,可以使用--depending
以下选项运行:
rpmdep -all --depending | tac | less -S
答案3
我曾经为此给自己写过一个脚本,但我几乎从未使用过它。
我会小心处理搬迁事宜。我曾经尝试删除一个名为“SimplyHTML”的包,因为它作为“叶节点”出现,当我去删除它时,发现“freemind”(我经常使用的思维导图工具)需要它并得到了也删除了。很奇怪!
无论如何,FWIW 这是脚本(在我的系统上称为“leaf-rpms”):
#!/usr/bin/perl
use strict;
use warnings;
use 5.10.0;
use Data::Dumper;
# a leaf RPM is one that has no deps and you can safely delete
# run it as is, delete any that you think are useless
my @installed = `rpm -qa --queryformat="%{NAME}\n"`;
chomp(@installed);
my %count;
@ARGV = ("dnf repograph |");
while (<>) {
chomp;
next if /^digraph packages/;
next unless m({) .. m(});
next if m({) or m(});
s/"//g;
$count{$_}++;
}
# print Dumper \@installed;
# print Dumper \@all;
# print Dumper \%count;
# print "----\n";
my %dup;
for my $k (sort @installed) {
next if $dup{$k}++;
print "$k\n" unless exists $count{$k};
}