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

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.
dnf Command Syntax
The basic dnf syntax is:
dnf [OPTIONS] COMMAND [PACKAGE|PATTERN]For commands that change the system, such as installing, removing, or upgrading packages, run dnf with sudo:
sudo dnf install package_nameOn Fedora 41 and later, the dnf command is backed by DNF5. RHEL-family distributions may still use DNF4 behavior depending on the release, which matters most for repository management commands.
Checking for Updates
Before installing or upgrading packages, check which packages have updates available:
dnf check-updateThe command lists all packages with available updates and returns exit code 100 if updates are available, or 0 if the system is up to date. This makes it useful in scripts.
Upgrading Packages
To upgrade all installed packages to their latest available versions, run:
sudo dnf upgradeTo refresh the repository metadata and upgrade in one step:
sudo dnf upgrade --refreshTo upgrade a single package:
sudo dnf upgrade package_nameTo apply only security updates:
sudo dnf upgrade --securityInstalling Packages
To install a package, run:
sudo dnf install package_nameTo skip the confirmation prompt, add the -y (--assumeyes) flag. This is common in scripts and automated setups where no interactive input is available:
sudo dnf install -y package_nameThe 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:
sudo dnf install package1 package2To install a local RPM file, provide the full path:
sudo dnf install /full/path/package.rpmdnf automatically resolves and installs all required dependencies.
To reinstall a package (for example, to restore corrupted files):
sudo dnf reinstall package_nameRemoving Packages
To remove an installed package:
sudo dnf remove package_nameYou can specify multiple packages separated by spaces:
sudo dnf remove package1 package2The 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:
sudo dnf autoremoveSearching for Packages
To search for a package by name or description:
dnf search package_nameThe command searches both package names and summaries. To search only in package names:
dnf search --names-only package_namePackage Information
To display detailed information about a package, including its version, repository, size, and description:
dnf info package_nameThis works for both installed and available packages.
Finding Which Package Provides a File
To find which package provides a specific file or command:
dnf provides /usr/bin/curlThis is useful when a command is missing and you need to know which package to install.
Listing Packages
To list all installed packages:
dnf list installedTo list all available packages from enabled repositories:
dnf list availableTo check whether a specific package is installed:
dnf list installed package_nameTo list packages that have updates available:
dnf list updatesPackage Groups
DNF organizes related packages into groups. To list all available groups:
dnf group listTo install a group (for example, “Development Tools”):
sudo dnf group install "Development Tools"To remove a group:
sudo dnf group remove "Development Tools"Module Streams
DNF modules allow you to install specific versions (streams) of software from repositories that provide modular content. They are common on RHEL and AppStream-based systems, but may not be available for every distribution or package. For example, a repository may let you choose between Node.js 18 and 20.
To list available modules:
dnf module listTo enable a specific module stream:
sudo dnf module enable nodejs:20To install a module with its default profile:
sudo dnf module install nodejs:20To reset a module to its default state:
sudo dnf module reset nodejsManaging Repositories
Use dnf repolist to inspect enabled repositories:
dnf repolistTo list all repositories, including disabled ones:
dnf repolist allOn Fedora releases that use DNF5, enable a repository with config-manager setopt:
sudo dnf config-manager setopt repo_id.enabled=1Disable it by setting the same option to 0:
sudo dnf config-manager setopt repo_id.enabled=0On DNF4-based systems, such as many current RHEL-family releases, install the plugin package if the subcommand is missing:
sudo dnf install dnf-plugins-coreThen use the older enable and disable syntax:
sudo dnf config-manager --set-enabled repo_id
sudo dnf config-manager --set-disabled repo_idTo show detailed information about a repository:
dnf repoinfo repo_idCleaning the Cache
DNF caches repository metadata and downloaded packages locally. To clear all cached data:
sudo dnf clean allTo rebuild the metadata cache:
sudo dnf makecacheCleaning 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:
dnf historyTo see the details of a specific transaction:
dnf history info 25To undo a transaction (revert the changes it made):
sudo dnf history undo 25This is useful when an upgrade causes problems and you need to roll back.
Quick Reference
For a printable quick reference, see the DNF cheatsheet .
| Task | Command |
|---|---|
| Check for available updates | dnf check-update |
| Upgrade all packages | sudo dnf upgrade |
| Install a package | sudo dnf install package_name |
| Install without confirmation | sudo dnf install -y package_name |
| Install a local RPM file | sudo dnf install /path/file.rpm |
| Remove a package | sudo dnf remove package_name |
| Remove unused dependencies | sudo dnf autoremove |
| Search for a package | dnf search keyword |
| Show package details | dnf info package_name |
| Find which package provides a file | dnf provides /path/to/file |
| List installed packages | dnf list installed |
| List enabled repositories | dnf repolist |
| Enable a repository on DNF5 | sudo dnf config-manager setopt repo_id.enabled=1 |
| Clear cached data | sudo dnf clean all |
| View transaction history | dnf history |
| Undo a transaction | sudo 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
If a dependency conflict prevents an upgrade, review the error message carefully. You can retry with sudo dnf upgrade --allowerasing, but only after confirming which packages will be removed.
“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 GPG key is not imported. DNF prompts you to accept the key during the first install from a new repository. If you need to import it manually, use sudo rpm --import KEY_URL.
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?
Specify the version with a dash: sudo dnf install package_name-1.2.3. To list all available versions, use dnf --showduplicates list package_name.
How do I prevent a package from being upgraded?
Use the versionlock plugin: sudo dnf install 'dnf-command(versionlock)', then sudo dnf versionlock add package_name. To remove the lock later, use sudo dnf versionlock delete package_name.
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.
Tags
Linuxize Weekly Newsletter
A quick weekly roundup of new tutorials, news, and tips.
About the authors

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