Dandified Yum (DNF) is a powerful package management front-end for RPM-based Linux distros. Here we show you everything that you need to know about the DNF package manager and the various DNF commands you can use to manage your packages.
Content
- Why Use DNF Package Manager?
- Installing Packages using DNF
- Handling Package Groups in DNF
- Searching for Available Packages
- Fetching Package Lists in DNF
- Upgrading System Packages
- Uninstalling System Packages using DNF
- Rolling Back System Changes in DNF
- Analyzing Existing System Packages
- Managing Repositories in DNF
Why Use DNF Package Manager?
Many Linux distros, such as Red Hat Enterprise Linux, CentOS Stream, and Fedora Linux have their own repositories that use RPM Package Manager (RPM) files to distribute programs, documentation, and libraries. It’s a compressed archive format that can run scripts, verify its internal content, and store package metadata.
One downside of RPM is that it can’t install a package unless its prerequisites are in the system. DNF bridges this gap by fetching the required dependencies for your package and resolving any software conflicts during installation.
Aside from that, DNF also provides additional tools for installing and managing packages in your system. It includes the ability to add external repos, search for remote content, as well as proper system cleanup and rollback support.
Good to know: learn more about other RPM-based Linux distros by looking at AlmaLinux vs. Rocky Linux.
Installing Packages using DNF
Installing packages is the fundamental function of every package manager. To install a remote package in DNF, run dnf install
followed by the package name:
sudo dnf install nano
The install
subcommand has a number of flags that allow you to change its default behavior. For instance, you can include the --setopt=install_weak_deps=False
to skip “Weak Dependencies” when installing a program.
Tip: Are you looking to secure your Linux installation? Learn how to encrypt file in Linux with Tomb.
Fetching and Installing RPM Files with DNF
DNF can also fetch bare .rpm packages from your upstream repo. This can be useful if you’re setting up an offline machine and you want to sideload RPM packages to it.
sudo dnf download emacs
You can even use the install
subcommand on your .rpm file to install it to your machine. Doing this will give you the benefit of dependency resolution for your non-repo packages.
sudo dnf install ~/your-package.rpm
Reinstalling Existing Packages
Further, DNF can force reinstall programs in your current machine. This can be useful if you’re having an issue with an existing package and you want to make sure that you’ve installed it properly.
sudo dnf reinstall nano
The reinstall
subcommand also takes a number of optional flags which modify its behavior. For example, the --allowerasing
flag will remove any potential dependency conflict as soon as you reinstall your program.
Tip: learn how you can fix broken package installs in Linux.
Handling Package Groups in DNF
Package groups are a unique DNF feature for installing programs around a theme or tool. This can be useful if you want to set up a consistent desktop build or manage collections of software.
To look at the available package groups for your system, run the following command:
dnf group list
You can check the content of a package group by running the info
argument after the group
subcommand. For instance, running dnf groups info Editors
will print a short description of the group and the packages it will install.
Installing and Removing Package Groups
The group
subcommand also handles its own installation process. Run the group
subcommand with the install
argument, then provide the name of the group that you want for your system:
sudo dnf group install Editors
To remove an entire package group, replace the install
argument with remove
followed by the name of the group that you want to remove:
sudo dnf group remove Editors
Searching for Available Packages
One important feature of every package manager is its ability to look through remote repos for available programs. To do this in DNF, use the search
subcommand:
dnf search nano
By default, DNF matches your search query to both the remote package’s name and its brief summary. You can change this behavior to include all the available metadata fields by adding the --all
flag:
dnf search --all nano
Advanced Package Search in DNF
In addition to “search,” DNF also comes with the repoquery
subcommand which allows you to look for packages and print them in “NEVRA” format. This is useful if you’re creating a script that will install specific packages using DNF and RPM.
The following command prints all the available “emacs” packages for Fedora 40 in NEVRA format:
dnf repoquery emacs
Aside from that, the repoquery
subcommand takes additional filter flags which you can use to refine your package searches. For example, the --installed
flag will only show packages on your machine and the --depends
will print that package’s dependencies:
dnf repoquery --installed --depends emacs
Fetching Package Lists in DNF
The list
subcommand is a flexible way of trowelling through the available DNF packages from your local machine and remote repos. For instance, the following command lists all the installed packages in your system.
dnf list --installed
Similar to repoquery
, the list
subcommand can take additional filter flags, such as --recent
, that will print the most recent packages available on your remote repos.
dnf list --recent
Further, the list
subcommand can also be a handy tool to quickly check on the available upgrades for your system:
dnf list --upgrades
This feature also extends to DNF’s maintenance-oriented subcommands. For example, the --autoremove
flag lists all the hanging dependencies on the system:
dnf list --autoremove
Upgrading System Packages
With DNF, you can upgrade all installed packages with one subcommand: upgrade
. This means that upgrading the system always meant that you’ll get the latest available version of your packages:
sudo dnf upgrade
If you just want to check for updates, use the check-update
subcommand instead:
sudo dnf check-update
Running Minimal System Upgrades
Aside from that, DNF can do “conservative upgrades” where it will only install security and bug fixes for existing programs. This is useful when you’re running a critical service, and you don’t want to introduce breaking changes to the machine:
sudo dnf upgrade-minimal
FYI: learn how to protect your data from malicious actors by installing some of the best Linux-libre distros today.
Upgrading and Downgrading Individual Packages
That said, you can upgrade individual packages by providing their name after the upgrade
subcommand. For instance, the following updates GNU Emacs to version 29.3 in Fedora 40:
sudo dnf upgrade emacs-1:29.3-6.fc40.x86_64
On the other hand, DNF also supports downgrading packages provided that a lower version exists in a currently active remote repo:
sudo dnf downgrade emacs
Note: Running the downgrade
subcommand will lower the version number of any package that is a hard dependency to your program.
Using Security Advisories to Upgrade Packages
Security advisories are a vital part of keeping up to date with the latest software vulnerabilities. To this end, DNF provides the --advisory
and --cve
flags which accepts Fedora Security Advisory codes and CVE ID numbers.
For example, the following command upgrades the xz library in a Fedora 40 system to address a severe security exploit:
sudo dnf upgrade --refresh --advisory=FEDORA-2024-d02c7bb266
Uninstalling System Packages using DNF
To uninstall packages, the remove
subcommand will remove packages from your system:
sudo dnf remove nano
Similar to Debian and Ubuntu, DNF provides a subcommand for removing “hanging” dependency files. To remove these unnecessary packages from your machine, run the following:
sudo dnf autoremove
Removing Package and Repository Metadata
Apart from hanging dependencies, DNF also creates additional metadata and cache files when you install or modify a package. This can be an issue if you want to save space on a storage-limited machine.
To fix this, run the clean
subcommand followed by “all”:
sudo dnf clean all
The clean
subcommand can also remove specific cache files instead of removing everything at once. For example, you can run dnf clean
with the “packages” argument to remove all cached package files without deleting any metadata:
sudo dnf clean packages
In addition to “all” and “packages,” dnf clean
accepts “dbcache,” “expire-cache,” and “metadata.” The first clears the cached metadata, the second forces a cache validation check, and the third deletes the metadata entirely.
Good to know: learn some of the best ways to securely delete files in Linux.
Rolling Back System Changes in DNF
Another key feature of DNF is its ability to go through its own package manager history and undo the changes that it did to the system. This can be useful if you’ve made a mistake while configuring your machine and you want to go back to a previous clean state.
To start, print the current history log for your system:
dnf history
Find a point in your system where you want to roll back to. In my case, I will select roll back my system to just before I installed Emacs.
Get the ID number of your transaction point, then run the following command to start the roll back:
sudo dnf history rollback ID-NUMBER
Confirm that DNF has rolled your system back to your transaction point by running: dnf history
.
You can also remove individual transactions by using the “undo” argument. For example, the following command removes Emacs on my system but doesn’t touch my later NodeJS installation:
sudo dnf history undo ID-NUMBER
Note: The undo argument does the opposite of the transaction command in dnf history
. This means that you can run dnf history undo
on a dnf remove
command to reinstall an old package.
Analyzing Existing System Packages
The DNF package manager also provides tools and flags to analyze RPM packages on both local and remote repos. For instance, the dnf info
command displays a detailed summary of any RPM file:
dnf info nano
Aside from reading a package’s details, you can also use DNF to check where a particular config file or binary came from. To do this, run the provides
subcommand followed by the absolute path of the file that you’re checking:
dnf provides /usr/bin/less
Managing Repositories in DNF
Repositories are the lifeblood of the every package manager. They serve as your machine’s source of new packages and updates. To this end, DNF also provides a wealth of tools to handle repo management including the ability to add, remove, and toggle them at will.
To add a new repository for DNF, run the config-manager
subcommand with the --add-repo
flag followed by the URL of your third-party repo. For example, the following command will add the Tailscale repository to your Fedora system:
sudo dnf config-manager --add-repo=https://pkgs.tailscale.com/stable/fedora/tailscale.repo
You can list all the active repositories as well as their repo ID in your system by running: dnf repolist --enabled
.
To disable an active repository, run config-manager
with the --disable
flag followed by the ID of the repo that you want to disable:
sudo dnf config-manager --disable tailscale-stable
Note: You can re-enable a disabled repository by using the --enable
flag along with the disabled repo’s ID.
Removing an Active Repository in DNF
Start by running the following command to list all the available repos in the system along with their file paths:
grep -E "^\[.*]" /etc/yum.repos.d/*
Find the repo that you want to remove from the list, then copy it to your clipboard. In my case, I will remove the Tailscale DNF repository from my machine.
Delete the .repo file from your system by running sudo rm
followed by the file path in your clipboard.
Run sudo dnf check-update
to refresh your machine’s repository listings.
Learning the basics of DNF is just the first step in understanding the intricate world of package managers in Linux. Explore more of this diverse ecosystem by looking at our comprehensive Linux package manager cheatsheet.
Image credit: Joan Gamell via Unsplash and Wikimedia Commons. All alterations and screenshots by Ramces Red.
Ramces Red –
Staff Writer
Ramces is a technology writer that lived with computers all his life. A prolific reader and a student of Anthropology, he is an eccentric character that writes articles about Linux and anything *nix.
Subscribe to our newsletter!
Our latest tutorials delivered straight to your inbox
Sign up for all newsletters.
By signing up, you agree to our Privacy Policy and European users agree to the data transfer policy. We will not share your data and you can unsubscribe at any time. Subscribe