20 DNF Commands Every Linux Administrator Should Know

Most people treat dnf as a drop-in replacement for yum and stop there. But that misses a lot of what makes DNF worth learning; automatic dependency resolution, transaction history with full undo support, module streams, and a plugin system that goes beyond what yum offered.

DNF (Dandified YUM) has been the default package manager on Fedora since Fedora 22 (2015) and on RHEL since RHEL 8 (2019). It is used across RHEL 8/9/10, Rocky Linux, AlmaLinux, CentOS Stream, and Fedora. If you’re still typing yum on any of these systems, it is usually linked or aliased to DNF anyway.

One important distinction for 2025/2026 is DNF5. DNF5 is a complete C++ rewrite of DNF and is now the default package manager on Fedora 41 and later, including Fedora 44, the current release.

On Fedora 41+, /usr/bin/dnf is a symlink to /usr/bin/dnf5 for backward compatibility, so the commands in this article still work. However, if you’re using Fedora 41 or later, writing dnf5 explicitly is recommended.

On the enterprise side, RHEL 9, Rocky Linux 9, AlmaLinux 9, and RHEL 10 still use DNF (dnf4) as the default package manager. DNF5 has not yet replaced DNF on these systems.

All examples below are tested on RHEL 9, Rocky Linux 9, and Fedora 44. A dedicated DNF5 section at the end of this article covers what changes on Fedora 41+.

Prerequisites: You need a working RHEL 8/9/10, Rocky Linux, AlmaLinux, or Fedora system. Most commands require sudo or root privileges; commands that don’t are noted accordingly.

TecMint Weekly Newsletter
Get the Learn Linux 7 Days Crash Course free when you join 34,000+ Linux professionals reading every Thursday.
Check your email for a magic link to get started.
Something went wrong. Please try again.

1. Install a Package

sudo dnf install nginx

DNF automatically resolves and installs all required dependencies. You can also install multiple packages with a single command:

sudo dnf install git curl wget vim

To skip the confirmation prompt, use -y. This is especially useful in scripts:

sudo dnf install -y nginx

2. Remove a Package

sudo dnf remove nginx

This removes the package but does not automatically remove all of its dependencies. If you also want to remove packages that were installed as dependencies and are no longer required, use autoremove instead (see Example 8).

If you’ve been typing yum out of habit, share this DNF has features that make package management genuinely faster.

3. Update a Single Package

sudo dnf update nginx

In DNF, update and upgrade are equivalent. Both update packages and handle obsolete packages, so there is no practical difference between the two commands.

4. Update All Packages

sudo dnf update

This updates all installed packages to the latest versions available from your enabled repositories. Before making any changes, you can check whether updates are available:

sudo dnf check-update

check-update returns exit code 100 when updates are available and 0 when the system is up to date. This makes it useful in scripts and cron jobs.

5. Search for a Package

dnf search nginx

To search both package names and package descriptions, use:

dnf search all nginx

The results include the package name, architecture, and a short summary. You don’t need sudo for package searches.

6. Get Package Information

dnf info nginx

This displays details such as the version, release, architecture, installed size, source repository, summary, and description without installing the package.

To view information about a package that is already installed:

dnf info --installed nginx

7. List Installed Packages

dnf list --installed

To check whether a specific package is installed, filter the output with grep command:

dnf list --installed | grep nginx

To list packages available from your enabled repositories, whether installed or not:

dnf list --available
Know a sysadmin still using rpm -qa | grep to check installed packages? Share this dnf list --installed is cleaner.

8. Remove Unused Dependencies

As you install and remove packages over time, some dependencies may no longer be needed. DNF can identify and remove these orphaned packages with autoremove:

sudo dnf autoremove

Run it periodically to keep your system clean. DNF only removes packages that were installed as dependencies and are no longer required by any installed package.

9. Clean the DNF Cache

DNF stores package metadata and downloaded RPMs in /var/cache/dnf. You can clean the cache if a repository is returning stale data or you’re running low on disk space:

sudo dnf clean all

To clean only the metadata while keeping downloaded packages:

sudo dnf clean metadata

After cleaning the metadata, the next dnf command downloads fresh metadata from all enabled repositories.

Learning Linux commands from scratch? The 100+ Essential Linux Commands course on Pro TecMint covers package management, file handling, process control, and 90+ other commands, each explained with real output and hands-on exercises.

10. View Transaction History

DNF keeps a transaction history of package installations, updates, and removals. To view recent transactions:

dnf history

You may see output like this:

ID     | Command line                        | Date and time    | Action(s) | Altered
-------+-------------------------------------+------------------+-----------+--------
    12 | install nginx                       | 2026-08-14 09:31 | Install   |      3
    11 | update                              | 2026-08-12 14:05 | Upgrade   |     47
    10 | remove vim-enhanced                 | 2026-08-10 11:22 | Removed   |      1

Each transaction has a unique ID that you can use to inspect what happened. For example:

dnf history info 12

This shows the packages affected by transaction 12, along with additional transaction details.

11. Undo a Transaction

One of DNF’s most useful features is the ability to undo a previous transaction using its ID.

For example:

sudo dnf history undo 12

DNF attempts to reverse transaction 12. If the transaction installed three packages, those packages are removed. If it upgraded packages, DNF attempts to restore their previous versions.

You can also redo a transaction that was previously undone:

sudo dnf history redo 12
The dnf history undo command can be a lifesaver when a package change causes unexpected problems. Share this, so your team knows it exists.

12. Downgrade a Package

If a newer package version causes problems, you can downgrade it to an older available version:

sudo dnf downgrade nginx

DNF selects the highest available version that is older than the currently installed version.

To install a specific version instead, specify the complete package version:

sudo dnf install nginx-1.24.0-1.el9.x86_64

13. Install a Local RPM File

If you’ve downloaded an RPM file manually, you can install it by passing its path directly to dnf install. Unlike rpm -i, DNF can resolve and install missing dependencies from your configured repositories:

sudo dnf install /tmp/package.rpm

14. List and Manage Repositories

To list all enabled repositories and their status:

dnf repolist

To see both enabled and disabled repositories:

dnf repolist --all

You can enable or disable a repository for a single command using --enablerepo and --disablerepo:

sudo dnf install --enablerepo=crb curl
sudo dnf update --disablerepo=epel

To permanently enable or disable a repository:

sudo dnf config-manager --enable crb
sudo dnf config-manager --disable epel
Running RHEL 9 or Rocky Linux in production? The RHCSA Certification Course on Pro TecMint covers DNF, repository management, SELinux, storage, and everything in the EX200 exam updated for RHEL 10

15. Add a New Repository

To add a repository using its URL:

sudo dnf config-manager --add-repo https://download.docker.com/linux/rhel/docker-ce.repo

Repository configuration files are stored in /etc/yum.repos.d/. After adding a repository, verify that it appears in the repository list:

dnf repolist

16. Install a Package Group

DNF supports package groups, which are collections of related packages that can be installed together. To see the available groups:

dnf group list

To install a group:

sudo dnf group install "Development Tools"

To remove a group:

sudo dnf group remove "Development Tools"

17. Work with Module Streams

Note: Module streams apply to RHEL 8/9, Rocky Linux, and AlmaLinux. Fedora retired modularity in Fedora 39, so on Fedora 40 and later, you install specific package versions directly from the repositories or use third-party repositories instead.

On RHEL 9 and Rocky Linux 9, DNF modules allow you to work with different versions of a package; for example, Node.js 18 or Node.js 20 without adding third-party repositories:

# List available module streams
dnf module list nodejs

# Enable a specific stream
sudo dnf module enable nodejs:20

# Install the module
sudo dnf module install nodejs:20

To switch to a different stream:

sudo dnf module reset nodejs
sudo dnf module enable nodejs:22
sudo dnf module install nodejs:22

On RHEL 10, module streams continue to be supported with an updated set of available streams. Run dnf module list on your system to see the current catalog.

18. Find Which Package Provides a File

When a command is missing, and you need to find out which package provides it, use dnf provides:

dnf provides /usr/bin/netstat
dnf provides */netstat

For example, the output may look like this:

net-tools-2.0-0.62.20160912git.el9.x86_64 : Basic networking tools
Repo        : baseos
Matched from:
Filename    : /usr/bin/netstat

This tells you that the net-tools package provides /usr/bin/netstat.

19. Reinstall a Package

If a package’s files are corrupted or accidentally deleted, you can reinstall the package without changing its version:

sudo dnf reinstall nginx

DNF downloads and reinstalls the same version that is currently recorded as installed.

20. Check and Verify Installed Packages

To check for broken dependencies across installed packages:

sudo dnf check

To verify the integrity of a specific package’s installed files against the RPM database, use:

rpm -V nginx

If everything is intact, the command produces no output. If you see any lines, they indicate files that differ from the original package. This can help identify accidental changes or corrupted files.

Got a colleague moving from Ubuntu to RHEL? Share this DNF is one of the first things they’ll need to get comfortable with.

DNF vs YUM vs DNF5: Key Differences

Feature YUM DNF (dnf4) DNF5
Language Python Python C++
Dependency resolution Custom solver (error-prone) libsolv (accurate) libsolv (faster)
API Undocumented Fully documented Fully documented
Plugin support Python only Python + C Python + C + C++
Transaction history & undo No Yes Yes
Module streams No Yes (RHEL/Rocky) Basic (RHEL/Rocky)
Python dependency Yes Yes No
Memory usage High Medium Low
Default since RHEL 6/7 RHEL 8, Fedora 22 Fedora 41+
Current status Symlink to DNF Default on RHEL 8/9/10 Default on Fedora 41+

DNF5 on Fedora 41 and Later

DNF5 is a ground-up rewrite of DNF in C++. It removes the Python dependency, processes metadata faster, uses less memory, and provides a cleaner, more consistent command-line interface.

DNF5 became the default package manager in Fedora 41, released in October 2024, and remains the default in later releases, including Fedora 44. On Fedora 41 and later, /usr/bin/dnf points to /usr/bin/dnf5, so the commands in this article continue to work as expected. However, using dnf5 explicitly is recommended going forward.

Most commands are the same in DNF and DNF5. Here are the differences worth knowing.

Install, Remove, and Update – Same Basic Syntax

sudo dnf5 install nginx
sudo dnf5 remove nginx
sudo dnf5 upgrade
sudo dnf5 upgrade nginx

With DNF5, upgrade is the preferred command for updating packages. update is still available as an alias, but upgrade is the canonical command.

Search and Info – Same Syntax

dnf5 search nginx
dnf5 info nginx

Repository Management – Slightly Different Flags

DNF5 includes config-manager as a built-in subcommand, so you don’t need a separate plugin for it.

To add a repository:

sudo dnf5 config-manager addrepo --from-repofile=https://download.docker.com/linux/rhel/docker-ce.repo

To enable or disable a repository:

sudo dnf5 config-manager setopt epel.enabled=1
sudo dnf5 config-manager setopt epel.enabled=0

Clean the Cache

To remove cached metadata and packages:

sudo dnf5 clean all

DNF5 uses check-upgrade as the preferred command instead of check-update. The older check-update command is still available as an alias.

What’s Not in DNF5 Yet

Module streams have only basic support in DNF5 on Fedora. Fedora retired modularity in Fedora 39, so this is generally not relevant to current Fedora releases.

On RHEL and Rocky Linux, DNF4 remains the default and provides full module stream support. DNF5 is not yet the default on RHEL 9, RHEL 10, Rocky Linux, or AlmaLinux, so use the standard dnf commands on those systems.

Quick Reference

Command What It Does
dnf install pkg Install a package
dnf remove pkg Remove a package
dnf update Update all packages
dnf check-update List available updates (no changes)
dnf search pkg Search by name
dnf info pkg Show package details
dnf list --installed List installed packages
dnf autoremove Remove unused dependencies
dnf clean all Clear cache
dnf history View transaction history
dnf history undo N Roll back transaction N
dnf downgrade pkg Downgrade to previous version
dnf provides */file Find which package owns a file
dnf repolist --all List all repositories
dnf group install "name" Install a package group
dnf module list List available module streams (RHEL/Rocky only)
dnf reinstall pkg Reinstall without changing the version
dnf check Check for broken dependencies
dnf5 upgrade Update all packages (Fedora 41+)
dnf5 check-upgrade Check for updates without applying them (Fedora 41+)
dnf5 history undo N Roll back transaction N (Fedora 41+)
Conclusion

DNF is much more than a replacement for yum. It gives you better dependency resolution, transaction history, package rollback, repository management, package groups, and tools for finding and troubleshooting packages.

For RHEL, Rocky Linux, AlmaLinux, and CentOS Stream, getting comfortable with dnf is an essential part of managing modern RPM-based systems. If you’re using Fedora 41 or later, you’ll also want to become familiar with DNF5 and its updated commands.

Once you know these commands, everyday package management becomes simpler, safer, and easier to troubleshoot whether you’re installing a single package or maintaining a production Linux server.

What’s the first DNF task you’d trust yourself to automate on a production server, and what’s the one you’d always run manually? Drop it in the comments the commands are simple, but knowing where to draw the line matters.

If this article helped, with someone on your team.

TecMint Weekly Newsletter
Get the Learn Linux 7 Days Crash Course free when you join 34,000+ Linux professionals reading every Thursday.
Check your email for a magic link to get started.
Something went wrong. Please try again.
TecMint has been free for 14 years. Help keep it that way.
Google AI Overviews and tools like ChatGPT have cut into search traffic for independent tech sites like TecMint. Running this site costs over $2,000 every month for hosting, infrastructure, and paying authors to keep the content accurate and tested.

There are two ways to help:
Anusha Saive
Anusha worked for many years in the IT industry as a Project Manager, and also a senior writer and editor at Tecmint. She is a huge fan of Linux and is passionate about writing Linux and technology-related stuff.

Each tutorial at TecMint is created by a team of experienced Linux system administrators so that it meets our high-quality standards.

12 Comments

Leave a Reply
  1. I have installed DNF in RHEL 7. While i try to update dnf, i got the below error.
    # dnf update
    “Failed to open: /var/cache/dnf/x86_64/7.1/x86_64/7.1/epel/repodata/78892cbf09fce6504b691ad19bf59507d65da9eacdebc0aa6ed1d053b502f829-updateinfo.xml.bz2.”

    Reply
    • @Ravichandran,

      Try to run following series of commands to fix that error.

      # dnf clean all
      # dnf repolist
      # dnf upgrade
      

      If you still see the same error, try to disable extra add-on repositories like EPEL or RepoForge, these repositories are for RHEL/CentOS Only.

      First, check your /etc/yum.repos.d/ directory, here if you find other than fedora.repo, fedora-updates.repo, and fedora-updates-testing.repo.

      Remove or disable them and then run the following command.

      # dnf dnf distro-sync
      

      Hope, it will fix your problem..

      Reply
      • i had alway find this problem but when i operated this what you told ,it doen’t work [duwenink@localhost ~]$ su
        密码:
        [root@localhost duwenink]# dnf clean all
        清理软件仓库: rpmfusion-free rpmfusion-free-updates fedora epel updates
        清理所有内容
        [root@localhost duwenink]# dnf repolist
        Extra Packages for Enterprise Linux 7 – x86_64 2.4 MB/s | 10 MB 00:04
        Failed to open: /var/cache/dnf/epel-2b6dfc5904c26562/repodata/b0b669b11555557436c35421a026af14feafd01ee60059737cddbc39853c66eb-updateinfo.xml.bz2.
        [root@localhost duwenink]# dnf upgrade
        RPM Fusion for Fedora 23 – Free 1.6 MB/s | 738 kB 00:00
        Failed to open: /var/cache/dnf/epel-2b6dfc5904c26562/repodata/b0b669b11555557436c35421a026af14feafd01ee60059737cddbc39853c66eb-updateinfo.xml.bz2.

        Reply
  2. You may wish to work on your english a bit because this is full of errors making it difficult to read, but thanks for the article.

    Reply
  3. Maybe you could write about how DNF/Libsolv/Hawkey compares to APT-GET and what the benefits are to using one over the other…

    Or possibly how the new Gnome 3 “Software” interacts with DNF.

    Reply
    • May be!

      But the theme of article was Yum replacement with DNF. As far as software interaction matters, let the project attain some level of maturity.

      Reply

Got Something to Say? Join the Discussion...

Thank you for taking the time to share your thoughts with us. We appreciate your decision to leave a comment and value your contribution to the discussion. It's important to note that we moderate all comments in accordance with our comment policy to ensure a respectful and constructive conversation.

Rest assured that your email address will remain private and will not be published or shared with anyone. We prioritize the privacy and security of our users.

Free Course
Get a free Linux course before you go.
Subscribe to TecMint Weekly and get the Learn Linux 7 Days Crash Course free. Read by 34,000+ Linux professionals every Thursday.
Something went wrong. Please try again.
Check your email for a magic link to get started.