dnf in a nutshell
dnf is a package manager for rpm-based linux distros; while rpm can only manage local repos, dnf can interact with both local and remote repos;
the full dnf command reference is long and takes some time to absorb; so we extract the most essential commands and give some brief introductions and examples, in a logical order;
make metadata
many dnf commands depend on having access to up-to-date repo metadata; to save the cost of accessing remote repo each time we run a command, this metadata is cached; the caching happens automatically when we run related commands; but in case we want to do it manually, use:
dnf makecache
clean metadata, packages and more
if the local cache of metadata, packages and other files are no longer needed, we can clean them using:
dnf clean [all|metadata|packages|...]
list repos
we can list enabled, disabled, or all repos using:
dnf repolist [--all|--enabled|--disabled]
install packages
to install one or more packages, use:
dnf install
upgrade packages
to upgrade one or more packages, use:
dnf upgrade
remove packages
to remove one or more packages, use:
dnf remove
list packages
to list packages, use:
dnf list [--all|--installed|--available|--upgrades|--extras|...]
show package infos
to show package infos, use:
dnf info [--all|--installed|--available|--upgrades|--extras|...]
query repos
now comes the repoquery
command:
dnf [options] repoquery [<select-options>] [<query-options>] [...]
this is a very powerful command to query packages in repos; fortunately, it is
an equivalent of rpm -q
for remote repos, so we do not have to cover it here
again; instead, we just give a few examples:
dnf repoquery gcc
dnf repoquery -i gcc
dnf repoquery -l gcc
dnf repoquery -f /usr/bin/bash
dnf --repo fedora repoquery -f /usr/bin/bash
in fact, dnf list
works like dnf repoquery
, and dnf info
works like dnf
repoquery -i
, in many aspects; but dnf list
and dnf info
give output that
is more human-readable;
transaction history
dnf keeps record of transactions we made in the past, and allows us to undo and
redo these transactions, using the history
command;
to list one, more or all historical transactions:
dnf history [list] [--reverse] [arg]
to show info of a transaction:
dnf history info <arg>
to undo a transaction:
dnf history undo <arg>
to redo a transaction:
dnf history redo <arg>
to rollback all transactions after the given one:
dnf history rollback <arg>
command alias
dnf allows user to define command aliases, using the alias
command;
to list aliases:
dnf alias [options] [list] [<name>...]
to create an alias:
dnf alias [options] add <name=value>
to delete an alias:
dnf alias [options] delete <name>
other useful commands
depending on use case, these commands can be useful:
autoremove
check
check-update
distro-sync
downgrade
group
mark
module
provides
search
updateinfo
global options
the dnf
command takes global options; here are a few useful ones:
-
--refresh
set metadata as expired before running the command; this option is strongly recommended for important jobs;
-
--allowerasing
allow erasing of installed packages to resolve dependencies; this option is necessary in certain cases, but use it with caution;
-
--repo=<repoid>, --repoid=<repoid>
enable just specific repositories by an id or a glob; can be used multiple times with accumulative effect;
-
-q, --quiet
show just relevant content and suppress notifying messages;
plugins
dnf can be augmented with plugins; some useful ones:
-
builddep
install build dependencies for package or spec file;
-
config-manager
manage dnf configuration options and repositories;
-
copr
interact with copr repositories;
-
download
download package to current directory;
-
repograph
output a full package dependency graph in dot format;
-
system-upgrade
prepare system for upgrade to a new release;
tips and tricks
-
dnf repoquery --requires --resolve <arg>
this command lists resolved dependencies of the given package; that is, it tells which packages must be installed before the given one;
-
dnf repoquery --whatprovides <arg>
this command is useful when we want to know which package provides the given capability; a capability is a text string, which can be a file path;
this command works like
dnf provides
; -
dnf repoquery --upgrades
this command works like
dnf check-update
; -
dnf upgrade --refresh
refresh metadata then upgrade all packages; do this before important jobs such as system upgrade;
-
dnf repoquery --unsatisfied
show broken dependencies among installed packages;
-
dnf repoquery --duplicates
show duplicate packages (packages with multiple versions installed);
-
dnf repoquery --extras
list packages installed on the system that are not available in any known repository;