Linux

DNF: Basic Commands for Package Management in Linux

This guide covers the essential DNF commands for package management. You'll learn how to update metadata, search for, install, remove packages, update the system, and clean the cache.

Updated at February 17, 2026
10-15 min
Easy
FixPedia Team
Применимо к:Fedora 38+RHEL 9+CentOS Stream 9+AlmaLinux 9+

Introduction / Why This Is Needed

DNF (Package Dandified with Yum) is a modern package manager for RPM-based Linux distributions such as Fedora, RHEL, CentOS, and their derivatives. It replaces the legacy YUM and offers improved dependency resolution, speed, and reliability. In this guide, you will master basic operations: updating metadata, searching, installing, removing packages, updating the system, and cleaning the cache. After completing these steps, you will be able to confidently manage software on your system.

Prerequisites / Preparation

Before you begin, ensure that:

  • You have terminal access with superuser privileges (sudo).
  • Your system is connected to the internet to download packages and metadata.
  • You are using a distribution that supports DNF (Fedora, RHEL 8+, CentOS 8+, AlmaLinux, RockyLinux, etc.).

⚠️ Important: All commands that modify the system (installation, removal, update) require superuser privileges. Always use sudo or switch to the root user.

Step 1: Update Repository Metadata

Before installing or updating packages, you must update the local cache of repository metadata. This ensures DNF is aware of the latest package versions and their dependencies.

sudo dnf makecache

The command downloads up-to-date package information from all enabled repositories and saves it to the cache. This is usually quick, but it may take a few minutes on first run or after a long interval.

Step 2: Search for a Package

To find a package by name or description, use dnf search:

dnf search <keyword>

For example, to search for packages related to JSON processing:

dnf search json

The results will show a list of packages whose name or description contains "json". For more precise searching, you can use a substring or regular expressions. If you know the exact package name, you can use dnf list available | grep <package_name>.

Step 3: Install a Package

Once you have found the desired package, install it using dnf install:

sudo dnf install <package_name>

For example, to install the jq utility (JSON processing):

sudo dnf install jq

DNF will automatically resolve dependencies and propose a list of packages for installation. Confirm the operation by pressing y (or use the -y flag for automatic confirmation: sudo dnf install -y jq).

💡 Tip: To install multiple packages simultaneously, list them separated by spaces: sudo dnf install package1 package2 package3.

Step 4: Remove a Package

To remove a package, use dnf remove:

sudo dnf remove <package_name>

For example:

sudo dnf remove jq

DNF will also remove dependencies that are no longer needed by any installed package (if they were installed automatically). To remove orphaned dependencies, you can use dnf autoremove (covered in the "Potential Issues" section).

Step 5: Update the System

To update all installed packages to the latest versions from the repositories, run:

sudo dnf update

Or with the -y flag for automatic confirmation:

sudo dnf update -y

This updates all packages except those excluded in the configuration. After an update, a reboot may be required if the kernel or critical libraries were updated.

⚠️ Important: Regular system updates are critical for security. Set up automatic updates or run sudo dnf update at least once a week.

Step 6: Clean DNF Cache

Over time, the DNF cache (downloaded packages and metadata) can consume significant disk space. To clean it, use:

sudo dnf clean all

This command removes all cached data, including package headers and downloaded RPM files. It is safe, but the next DNF operation will need to re-download metadata. For more targeted cleaning, you can use sudo dnf clean packages (only downloaded RPMs) or sudo dnf clean metadata (only metadata).

Verification

  • After installing a package: Check its presence with dnf list installed | grep <package_name> or run the package's binary file (if available).
  • After removal: Ensure the package is no longer in the list of installed packages (dnf list installed | grep <package_name> should output nothing).
  • After updating: Check versions of key packages or run dnf check-update to confirm there are no remaining updates.
  • After cleaning the cache: Verify that the /var/cache/dnf directory is empty or contains only temporary files.

Potential Issues

  1. Dependency resolution error: DNF cannot find compatible package versions.
    Solution: Try sudo dnf distro-sync to synchronize with repositories or disable conflicting repositories. sudo dnf autoremove to remove unnecessary packages may also help.
  2. Missing repository: Package not found.
    Solution: Ensure the repository containing the package is enabled. Check configuration in /etc/yum.repos.d/ and run sudo dnf repolist all. Add the repository manually if necessary.
  3. Access error: Running without sudo.
    Solution: All system-modifying operations require superuser privileges. Use sudo with commands or switch to root (su -).
  4. Insufficient disk space: Especially during system updates.
    Solution: Clean the cache (sudo dnf clean all) or remove unneeded packages (sudo dnf autoremove). Check free space with df -h.

F.A.Q.

How to update only one package using DNF?
What does the `dnf autoremove` command do?
How to add a third-party repository to DNF?
Why is DNF slow and how to speed it up?

Hints

Updating repository metadata
Searching for a package
Installing a package
Removing a package
Updating the system
Cleaning the DNF cache
FixPedia

Free encyclopedia for fixing errors. Step-by-step guides for Windows, Linux, macOS and more.

© 2026 FixPedia. All materials are available for free.

Made with for the community