dnf Command in Linux: Install, Update, and Manage Packages

By 

Updated on

12 min read

dnf command package management reference

When you manage software on Fedora, RHEL, Rocky Linux, AlmaLinux, or another RPM-based distribution, most package tasks go through dnf. You use it to install packages, apply updates, search repositories, clean caches, and inspect package history from the command line.

Most dnf commands require root privileges, so you need to run them with sudo .

This guide explains the most common dnf commands for day-to-day package management, including the newer DNF5 repository syntax used on current Fedora releases.

What Is DNF

DNF is the package manager used by Fedora, RHEL, and many other RPM-based distributions. It sits on top of rpm , which installs and removes individual package files but does not fetch them or resolve what else they need. DNF adds both halves: it reads the repositories configured on the system, works out the full set of packages a request depends on, downloads them, and hands them to RPM. The name is usually expanded as Dandified YUM, which points at its origin as a rewrite of the older yum tool.

Two generations of DNF are in circulation, and the difference surfaces in a few commands:

  • DNF4 is the original Python implementation. It shipped through Fedora 40 and is still what RHEL 9, RHEL 10, and their rebuilds use.
  • DNF5 is the C++ rewrite. It provides /usr/bin/dnf on Fedora 41 and later, and it changes repository management, group listing, and a handful of option names.

Installing, upgrading, removing, and searching work the same way on both. Where the two diverge, this guide shows each form.

Installing dnf

Fedora, RHEL, Rocky Linux, and AlmaLinux normally include dnf as part of the base system, so there is nothing to install before the commands in this guide work. To check which implementation you are running:

Terminal
dnf --version

DNF5 reports a version that starts with 5, and DNF4 reports one that starts with 4.

Debian and Ubuntu are a different case. A dnf package does exist in their archives, but its description states that it “requires a working rpm installation and is meant to be used in chroots”. It manages RPM packages inside a chroot rather than the deb packages on your system, so it is not a replacement for apt there.

dnf Command Syntax

The basic dnf syntax is:

txt
dnf [OPTIONS] COMMAND [PACKAGE|PATTERN]

For commands that change the system, such as installing, removing, or upgrading packages, run dnf with sudo:

Terminal
sudo dnf install package_name

Checking for Updates

Before installing or upgrading packages, check which packages have updates available:

Terminal
dnf check-update

The command lists all packages with available updates and returns exit code 100 if updates are available, 0 if the system is up to date, or 1 if an error occurs. Check for all three values when you use it in a script.

Upgrading Packages

To upgrade all installed packages to their latest available versions, run:

Terminal
sudo dnf upgrade

To refresh the repository metadata and upgrade in one step:

Terminal
sudo dnf upgrade --refresh

To upgrade a single package:

Terminal
sudo dnf upgrade package_name

To apply only security updates:

Terminal
sudo dnf upgrade --security

Installing Packages

To install a package, run:

Terminal
sudo dnf install package_name

To skip the confirmation prompt, add the -y (--assumeyes) flag. This is common in scripts and automated setups where no interactive input is available:

Terminal
sudo dnf install -y package_name

The same flag works with upgrade, remove, and other commands that ask for confirmation, for example sudo dnf upgrade -y.

To install multiple packages at once, specify them as a space-separated list:

Terminal
sudo dnf install package1 package2

To install a local RPM file, provide the full path:

Terminal
sudo dnf install /full/path/package.rpm

dnf automatically resolves and installs all required dependencies.

To reinstall a package (for example, to restore corrupted files):

Terminal
sudo dnf reinstall package_name

Installing a Specific Package Version

By default, dnf install picks the newest version the enabled repositories offer. When you need to hold an application at a known-good build, or reproduce an environment on another machine, start by listing every version that is actually available:

Terminal
dnf list --showduplicates package_name

Without --showduplicates, the command prints only the newest candidate, which is why a version you know exists can look like it is missing.

Once you have the version string, append it to the package name with a dash:

Terminal
sudo dnf install package_name-1.2.3

The full form of a package identifier is name-epoch:version-release.architecture, so you can be as specific as the situation requires. Adding the release and architecture pins one exact build:

Terminal
sudo dnf install nano-0:6.0-2.fc36.x86_64

If the package is already installed at a newer version, install will not move it backwards. Use downgrade for that:

Terminal
sudo dnf downgrade package_name

Called without a version, downgrade steps back to the highest installable version below the current one. You can also name the target directly, as in sudo dnf downgrade nano-0:6.0-2.fc36.

A version chosen this way only holds until the next dnf upgrade finds a newer build. To keep it in place permanently, lock it with the versionlock plugin described in the FAQ.

Removing Packages

To remove an installed package:

Terminal
sudo dnf remove package_name

You can specify multiple packages separated by spaces:

Terminal
sudo dnf remove package1 package2

The remove command also removes packages that depend on the one being removed.

Removing Unused Dependencies

When a package is removed, its dependencies may no longer be needed by any other package. To remove these orphaned dependencies:

Terminal
sudo dnf autoremove

Searching for Packages

To search for a package by name or description:

Terminal
dnf search package_name

The command searches both package names and summaries. On DNF5, use --name to search only in package names:

Terminal
dnf search --name package_name

DNF4 does not have the --name option. Use repoquery with a quoted glob to match package names instead:

Terminal
dnf repoquery '*package_name*'

Package Information

To display detailed information about a package, including its version, repository, size, and description:

Terminal
dnf info package_name

This works for both installed and available packages.

Finding Which Package Provides a File

To find which package provides a specific file or command:

Terminal
dnf provides /usr/bin/curl

This is useful when a command is missing and you need to know which package to install.

Listing Packages

To list all installed packages :

Terminal
dnf list --installed

To list all available packages from enabled repositories:

Terminal
dnf list --available

To check whether a specific package is installed:

Terminal
dnf list --installed package_name

To list packages that have updates available:

Terminal
dnf list --upgrades

Package Groups

DNF organizes related packages into groups. To list all available groups:

Terminal
dnf group list

To install a group (for example, “Development Tools”):

Terminal
sudo dnf group install "Development Tools"

To remove a group:

Terminal
sudo dnf group remove "Development Tools"

DNF4 listed environments, the larger collections behind desktop spins, together with ordinary groups. DNF5 separates them into their own command:

Terminal
dnf environment list

Module Streams

Modules were a way to ship several versions (streams) of the same software from one repository, so that you could pick Node.js 18 or Node.js 20 from the same AppStream. The feature is being retired, and on a current system you are unlikely to need it.

Fedora stopped shipping modular content in Fedora 39, and DNF5 implements only part of the module interface, so a call such as dnf module install fails with an unknown-argument error. RHEL 10 distributes no modular content either and prints a deprecation warning when the command is used. Application streams there are ordinary RPM packages that you install with dnf install.

Modules are still worth knowing on RHEL 8 and RHEL 9 and their rebuilds, where DNF4 supports them in full. To see what a repository offers:

Terminal
dnf module list

Enable the stream you want, then install it with its default profile:

Terminal
sudo dnf module enable nodejs:20
sudo dnf module install nodejs:20

Switching to a different stream later requires returning the module to its default state first:

Terminal
sudo dnf module reset nodejs

Managing Repositories

Use dnf repolist to inspect enabled repositories:

Terminal
dnf repolist

To list all repositories, including disabled ones:

Terminal
dnf repolist --all

On Fedora releases that use DNF5, enable a repository with config-manager setopt:

Terminal
sudo dnf config-manager setopt repo_id.enabled=1

Disable it by setting the same option to 0:

Terminal
sudo dnf config-manager setopt repo_id.enabled=0

On DNF4-based systems, such as many current RHEL-family releases, install the plugin package if the subcommand is missing:

Terminal
sudo dnf install dnf-plugins-core

Then use the older enable and disable syntax:

Terminal
sudo dnf config-manager --set-enabled repo_id
sudo dnf config-manager --set-disabled repo_id

To show detailed information about a repository:

Terminal
dnf repoinfo repo_id

Cleaning the Cache

DNF caches repository metadata and downloaded packages locally. To clear all cached data:

Terminal
sudo dnf clean all

To rebuild the metadata cache:

Terminal
sudo dnf makecache

Cleaning the cache is useful when you encounter stale metadata errors or want to free disk space.

Transaction History

DNF records every transaction (install, upgrade, remove) in a history log. To view the transaction history:

Terminal
dnf history list

To see the details of a specific transaction:

Terminal
dnf history info 25

To undo a transaction (revert the changes it made):

Terminal
sudo dnf history undo 25

This is useful when an upgrade causes problems and you need to roll back.

Quick Reference

For a printable quick reference, see the DNF cheatsheet .

TaskCommand
Check for available updatesdnf check-update
Upgrade all packagessudo dnf upgrade
Install a packagesudo dnf install package_name
Install without confirmationsudo dnf install -y package_name
Install a local RPM filesudo dnf install /path/file.rpm
List all available versionsdnf list --showduplicates package_name
Install a specific versionsudo dnf install package_name-1.2.3
Roll a package backsudo dnf downgrade package_name
Remove a packagesudo dnf remove package_name
Remove unused dependenciessudo dnf autoremove
Search for a packagednf search keyword
Show package detailsdnf info package_name
Find which package provides a filednf provides /path/to/file
List installed packagesdnf list --installed
List enabled repositoriesdnf repolist
Enable a repository on DNF5sudo dnf config-manager setopt repo_id.enabled=1
Clear cached datasudo dnf clean all
View transaction historydnf history list
Undo a transactionsudo dnf history undo ID

Troubleshooting

“Error: Failed to download metadata for repo”
The repository metadata is stale or the mirror is unreachable. Run sudo dnf clean all followed by sudo dnf makecache to refresh the cache. If the problem persists, check your network connection and the repository URL in /etc/yum.repos.d/.

“No match for argument: package_name”
The package does not exist in any enabled repository. Verify the package name with dnf search and check that the correct repository is enabled with dnf repolist.

Dependency conflict during upgrade
Read the error before reaching for a flag, because each of the escapes has a cost. sudo dnf upgrade --allowerasing lets DNF remove installed packages to resolve the conflict, so check the removal list before accepting the transaction. sudo dnf upgrade --skip-unavailable, spelled --skip-broken on DNF4, leaves the problem packages at their current version and upgrades the rest. Dropping the requirement to install the best candidate is --no-best on DNF5 and --nobest on DNF4, which is a common source of unknown-option errors when a command is copied between systems.

There is no –force option
dnf has no general --force flag. To restore a package whose files were damaged, run sudo dnf reinstall package_name. To move to an older build, run sudo dnf downgrade package_name. To push an upgrade past a conflict, use the options above rather than bypassing dependency resolution with rpm --force.

“Unknown argument –set-enabled” with config-manager
You are likely using DNF5. Use sudo dnf config-manager setopt repo_id.enabled=1 to enable the repository, or sudo dnf config-manager setopt repo_id.enabled=0 to disable it.

GPG key verification failed
The repository key may be missing, expired, rotated, or different from the key that signed the package or metadata. Do not disable GPG checks or import a key from an unverified URL. Confirm that the repository’s gpgkey= setting points to the publisher’s official key, compare its fingerprint with the publisher’s documentation, and then refresh the metadata. If you need to import a verified local key manually, use sudo rpmkeys --import /path/to/RPM-GPG-KEY.

Transaction undo fails
Not all transactions can be undone. If packages have been updated by later transactions, the undo may conflict. Check dnf history info ID for details and consider a manual rollback.

FAQ

What is the difference between dnf and yum?
dnf is the successor to yum. It uses the same repository format and configuration files, but provides faster dependency resolution, better memory usage, and a more consistent command interface. On modern Fedora and RHEL systems, yum is a symlink to dnf.

Is dnf update the same as dnf upgrade?
Yes. dnf update is an alias for dnf upgrade. Both commands upgrade all installed packages to the latest available versions.

How do I install a specific version of a package?
List the candidates with dnf list --showduplicates package_name, then append the version to the package name, as in sudo dnf install package_name-1.2.3. The Installing a Specific Package Version section covers the full package identifier and rolling back.

How do I prevent a package from being upgraded?
DNF5 includes versionlock in the main dnf5 package. DNF4 uses a separate plugin, which you can install with sudo dnf install 'dnf-command(versionlock)' if the command is unavailable. Once it is available, sudo dnf versionlock add package_name freezes the package at its installed version, dnf versionlock list shows the active locks, and sudo dnf versionlock delete package_name releases one.

What is the equivalent of apt autoremove in dnf?
The equivalent is sudo dnf autoremove. It removes packages that were installed as dependencies but are no longer required by any installed package.

Conclusion

dnf handles the main package management workflow on RPM-based distributions: installing, upgrading, removing, searching, and troubleshooting packages. Keep the DNF cheatsheet handy for the commands you use most often, and run man dnf when you need the full command reference.

Linuxize Weekly Newsletter

A quick weekly roundup of new tutorials, news, and tips.

About the authors

Dejan Panovski

Dejan Panovski

Dejan Panovski is the founder of Linuxize, an RHCSA-certified Linux system administrator and DevOps engineer based in Skopje, Macedonia. Author of 1000+ Linux tutorials with 20+ years of experience turning complex Linux tasks into clear, reliable guides.

View author page