Dnf Command in Linux: Package Management Guide
dnf (Dandified YUM) is the default package manager on Fedora, RHEL, AlmaLinux, Rocky Linux, and other RPM-based distributions. It replaces the older yum package manager and provides faster dependency resolution, better performance, and a cleaner command interface.
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.
Checking for Updates (dnf check-update)
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, or 0 if the system is up to date. This makes it useful in scripts.
Upgrading Packages (dnf upgrade)
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 (dnf install)
To install a package, run:
Terminal
sudo dnf install package_name
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
Removing Packages (dnf remove)
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 (dnf autoremove)
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 (dnf search)
To search for a package by name or description:
Terminal
dnf search package_name
The command searches both package names and summaries. To search only in package names:
Terminal
dnf search --names-only package_name
Package Information (dnf info)
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 (dnf provides)
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 (dnf list)
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 | grep package_name
To list packages that have updates available:
Terminal
dnf list updates
Package Groups (dnf group)
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"
Module Streams (dnf module)
DNF modules allow you to install specific versions (streams) of software. For example, you can choose between Node.js 18 or 20.
To list available modules:
Terminal
dnf module list
To enable a specific module stream:
Terminal
sudo dnf module enable nodejs:20
To install a module with its default profile:
Terminal
sudo dnf module install nodejs:20
To reset a module to its default state:
Terminal
sudo dnf module reset nodejs
Managing Repositories (dnf config-manager)
The config-manager command is provided by the dnf-plugins-core package. Install it first if the subcommand is missing:
Terminal
sudo dnf install dnf-plugins-core
To list all enabled repositories:
Terminal
dnf repolist
To list all repositories, including disabled ones:
Terminal
dnf repolist all
To enable a repository:
Terminal
sudo dnf config-manager --set-enabled repo_id
To disable a repository:
Terminal
sudo dnf config-manager --set-disabled repo_id
To show detailed information about a repository:
Terminal
dnf repoinfo repo_id
Cleaning the Cache (dnf clean)
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 history)
DNF records every transaction (install, upgrade, remove) in a history log. To view the transaction history:
Terminal
dnf history
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
| Task | Command |
|---|---|
| Check for available updates | dnf check-update |
| Upgrade all packages | sudo dnf upgrade |
| Install a package | sudo dnf install 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 |
| Clear cached data | sudo dnf clean all |
| View transaction history | dnf history |
| Undo a transaction | sudo dnf history undo ID |
For a printable quick reference, see the DNF cheatsheet
.
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.
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-plugin-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 is the standard package manager for Fedora, RHEL, and RPM-based distributions. It handles installing, upgrading, removing, and searching packages, as well as managing repositories and module streams. To learn more, run man dnf in your terminal.
If you have any questions, feel free to leave a comment below.
