如何對已安裝的rpm包進行拓樸排序?

如何對已安裝的rpm包進行拓樸排序?

我想根據依賴關係對 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

安裝:

rpm-devel fedora 19 有這個包

這是 Fedora 30 的 rpm-devel

使用你的套件管理器:

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};
}

相關內容