I want to sort topologically, according to dependencies, all installed rpm packages on my Fedora with most required packages to be on top (for example glibc) and least required packages to be on bottom. I can list all installed packages with rpm -qa, but they don't seem to be topologically sorted.

My goal is to review installed packages, find the ones I don't need anymore and uninstall them.

  • 3
    You might find package-cleanup --leaves useful
    – Jeff Schaller
    Commented Jun 5, 2019 at 14:24

3 Answers 3


man rpmgraph:

rpmgraph(8) - Linux man page
rpmgraph - Display RPM Package Dependency Graph

rpmgraph PACKAGE_FILE ...

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

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 has this package

Here is rpm-devel for fedora 30

Use your package manager:

dnf install rpm-devel

To install wget in CentOS, enter the following in a terminal window:

sudo yum install wget

To install wget in Fedora, enter the following:

sudo dnf install wget

Now, you can use the wget command to download the .rpm file you want. Enter the following:

wget http://some_website/sample_file.rpm

The system should reach out to the website and download the file to your current working directory.

Install RPM File Using RPM Command

To install a .rpm package in Fedora or CentOS Linux, enter the following:

sudo rpm –i sample_file.rpm

The –i switch tells the package manager you want to install the file.

More information on the RPM installer can be found in the RPM documentation.

Install RPM File With Yum

Alternately, you can use the yum package manager to install .rpm files.

Enter the following:

sudo yum localinstall sample_file.rpm

The localinstall option instructions yum to look at your current working directory for the installation file.





I can't get rpmgraph to work, I've tried three different versions of PACKAGE_FILE syntax of package list, but it just gives errors, If you know how to use this program, please provide an answer or edit mine. Tested on Fedora 28.How to list all installed packages with the .rpm extension. Fedora, Centos, RedHat

(null): read manifest failed:
  • Is github.com/htgoebel/rpmgraph the upstream, I wonder? Appears to be a single python file, there.
    – Jeff Schaller
    Commented Jun 5, 2019 at 15:11
  • @JeffSchaller I'm not sure, but what I can see it's not This utility is slightly different from the one coming with RPM:, hadn't seen that one thanks Commented Jun 5, 2019 at 15:15
  • But rpmgraph requires package files as arguments and generates a graph for these package files. I would like to get a topologically sorted list of all installed packages.
    – ks1322
    Commented Jun 5, 2019 at 15:26
  • @ks1322 yes that's something you can use this for, I'll update my answer Commented Jun 5, 2019 at 16:16

After searching a bit, it seems that rpmdep tool from rpmorphan package is the most close to what I want. To see the most required installed packages, it can be run with --depending option:

rpmdep -all --depending | tac | less -S

I once wrote myself a script for this, but I hardly ever used it.

I'd handle removals with care. I once tried to delete a package called "SimplyHTML" because it came up as a "leaf node", and when I went to remove it, found that "freemind" (a mind-mapping tool I use a lot) needed it and got deleted also. Very weird!

Anyway, FWIW here's the script (which on my system is called "leaf-rpms"):

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"`;
my %count;

@ARGV = ("dnf repograph |");

while (<>) {
    next if /^digraph packages/;
    next unless m({) .. m(});
    next if m({) or m(});

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .