I use DNF (Dandified YUM) whenever I install or update software on Fedora, RHEL, Rocky Linux, or another RPM-based system. This how-to gives you a single, clear path to install, update, remove, and search packages so you can get the task done and verify it.

## Goal

By the end you will have used DNF to install a package, update your system, remove a package, and search for packages. You will know how to confirm each step and fix the most common failures.

**Success criteria:** You can run `dnf install`, `dnf update`, `dnf remove`, and `dnf search` from the command line and interpret the output. You can confirm a package is installed and working.

**Scope:** This guide covers everyday DNF tasks on a single machine. It does not cover adding third-party repositories, modules and streams, or building packages from source.

**Assumptions:** Fedora, RHEL, Rocky Linux, AlmaLinux, or a close derivative. You have a terminal and either root or `sudo` access. Examples use a real package name (e.g. `nginx`) so you can copy and run them.

## Prerequisites

**Required knowledge:**

* Basic use of the terminal (running commands, reading output).
* How to run privileged commands (e.g. `sudo`).

**Required tools:**

* DNF, the default package manager on Fedora 22+ and RHEL 8+. Check with `dnf --version` or `which dnf`.

**Required access:**

* Ability to run commands as root (e.g. `sudo`); installing and removing packages require it.

## Steps

### Step 1: Refresh repository metadata

Before installing or upgrading, refresh the local copy of repository metadata so DNF knows the latest versions and dependencies. Choose one:

* **Check for updates and refresh metadata:** Use when you plan to upgrade or install and want to see what is available.
* **Refresh metadata only:** Use when you only want to update the cache without upgrading.

Check for updates and refresh metadata:

```bash
sudo dnf check-update
```

Refresh metadata only (no upgrade):

```bash
sudo dnf makecache
```

**Expected output:** For `dnf check-update`, a list of packages that have updates, or "Last metadata expiration check" and no package list if nothing is available. Exit code 0 means success. For `dnf makecache`, "Metadata cache created." Errors about repos or signatures mean a configuration problem; see Troubleshooting.

### Step 2: Install a package

Install a single package and its dependencies. Example: install the `nginx` web server.

```bash
sudo dnf install nginx
```

DNF will list the package(s) to be installed and the disk space needed, then prompt for confirmation (`y/N`). Answer `y` and press Enter. To avoid the prompt (e.g. in scripts), use `-y`:

```bash
sudo dnf install -y nginx
```

**Expected output:** Download progress, "Installing:" and "Installed:" lines, then "Complete!" The command exits 0 when the install completes. The package and its dependencies are then installed.

### Step 3: Confirm the package is installed

Check that the package is present and, if it provides a command, that the command runs. DNF uses RPM (RPM Package Manager) to record installed files; you can list them with `rpm -ql`.

```bash
dnf list installed | grep nginx
rpm -ql nginx
```

Optionally run the program (e.g. `nginx -v` or `which nginx`) to confirm it is on your PATH and working.

### Step 4: Upgrade installed packages

To upgrade all installed packages to the versions offered by your configured repositories, run:

```bash
sudo dnf update
```

DNF refreshes metadata if needed, then lists packages to upgrade and asks for confirmation. Use `-y` to skip the prompt when appropriate.

**Expected output:** A list of packages to be upgraded, download and install lines, then "Complete!" Exit code 0 means the upgrade completed. If the upgrade wants to remove or install additional packages, it will say so; review the summary before confirming.

**Warning:** `dnf update` can add or remove packages to satisfy dependencies. Always review the summary before confirming.

### Step 5: Remove a package

To remove a package but keep its configuration files (useful if you might reinstall later):

```bash
sudo dnf remove nginx
```

DNF removes only the specified package by default. If other packages depend on it, DNF may warn or refuse. To remove a package and optionally clean up dependencies that are no longer needed, use `dnf remove` then see Step 6.

**Expected output:** DNF lists the package(s) to be removed and asks for confirmation. After you confirm, it removes the package. Dependencies that are no longer required are not removed by default.

### Step 6: Remove unused dependencies (optional)

After removing packages, leftover dependencies can remain. To remove packages that were installed only as dependencies and are no longer needed:

```bash
sudo dnf autoremove
```

Review the list before confirming. This step is safe to run periodically to free disk space.

### Step 7: Search for packages

To find packages by name or description:

```bash
dnf search nginx
```

**Expected output:** A list of package names and short descriptions. Install the desired package with `sudo dnf install <package-name>`.

To show detailed information about a specific package (version, description, dependencies):

```bash
dnf info nginx
```

### Step 8: List files in a package (optional)

To see which files a package installed, use RPM after installing:

```bash
rpm -ql nginx
```

To inspect a package without installing it, download the RPM and list its contents:

```bash
dnf download nginx
rpm2cpio nginx-*.rpm | cpio -t
```

`dnf repoquery -l <package>` only shows files listed in repository metadata; some packages (e.g. modular or binary-only) do not expose a file list there, so "contains no files" can appear even though the package installs files. Use `rpm -ql` for installed packages.

## Verification

* **Install:** `dnf list installed | grep <package>` shows the package; the program runs (e.g. `nginx -v` or `which <command>`).
* **Upgrade:** After a successful update, `dnf check-update` reports no updates (or only those you chose not to apply).
* **Remove:** `dnf list installed | grep <package>` shows nothing; the binary is no longer on PATH.
* **Search:** `dnf search <term>` returns matching packages; `dnf info <package>` shows details for one package.

If any of these checks fail, re-run the corresponding step and check the command output for errors, then see Troubleshooting.

## Troubleshooting

### Problem: "No match for argument" or "Unable to find a match"

**Symptoms:** `dnf install <name>` reports "No match for argument" or "Unable to find a match."

**Solution:** Refresh metadata with `sudo dnf makecache` or `sudo dnf check-update`, then try again. If it still fails, the package name may be wrong (use `dnf search <term>`) or the package may not exist in your enabled repositories. Check that the correct repository is enabled for your release.

**If that doesn't work:** Confirm your distribution and release (e.g. `cat /etc/os-release`). Some packages are in optional or modular streams; see your distro's documentation on enabling them.

### Problem: Dependency resolution failures

**Symptoms:** DNF refuses to install or upgrade and reports dependency conflicts or unsolved dependencies.

**Solution:** Read the error message; DNF often names the conflicting packages. Ensure all enabled repositories are valid and up to date (`sudo dnf makecache`). If you added a third-party repo, ensure it matches your release and architecture. Try removing or disabling the conflicting repo temporarily to isolate the problem.

**If that doesn't work:** Check for broken or partial transactions with `sudo dnf clean all` and `sudo dnf makecache`, then retry. For persistent conflicts, your distro's documentation on "Managing software with DNF" or "Package management" usually covers repository priority and excludes.

### Problem: GPG or repository errors during refresh

**Symptoms:** Warnings like "GPG key retrieval failed" or "Cannot prepare internal mirrorlist" or repository signature errors.

**Solution:** Usually a repository is misconfigured or a GPG key is missing or expired. For official distro repos, ensure your release is still supported and repo files under `/etc/yum.repos.d/` are correct. For third-party repos, follow that project's instructions to add the key and the repo. Temporarily disabling the problematic repo (e.g. `dnf config-manager --set-disabled <repo-id>` or editing the `.repo` file) can isolate the bad repo.

**If that doesn't work:** Restore default repos for your distribution (Fedora and RHEL document "Repositories" and "Configuring repositories") and add third-party repos one at a time to find the failing one.

### Problem: "Another process is running" or lock errors

**Symptoms:** DNF reports that another DNF or RPM process is running, or a lock file is held.

**Solution:** Another DNF, YUM, or RPM process is running (e.g. Software application, automatic updates). Wait for it to finish, or close the other tool. Do not remove the lock file while another process is using it.

**If that doesn't work:** If you are sure no other DNF/RPM process is running (check with `ps aux | grep -E 'dnf|rpm|yum'`), you can remove the lock (e.g. `/var/lib/dnf/lock` or `/var/lib/rpm/.rpm.lock` depending on distro). Then run `sudo dnf makecache`. Use only when you understand the risk; interrupting a transaction can leave the database inconsistent.

### Problem: DNF is slow

**Symptoms:** Commands take a long time, especially the first run after boot or a long break.

**Solution:** DNF refreshes metadata from enabled repositories; with many repos or a slow network, this can take tens of seconds or more. Some slowness is normal. If it is always slow, reduce the number of enabled repos, check network connectivity, and ensure disk space and I/O are healthy (e.g. `/var/cache/dnf`). Use `dnf makecache` once so later commands can use cached metadata.

### Rollback

DNF transactions are atomic: on failure, DNF rolls back. To undo a successful install, run `sudo dnf remove <package>`. To revert an upgrade, you would need to install an older version from a snapshot or backup; that is beyond this how-to. For important changes, take a snapshot or backup before large upgrades.

## Related Content

* [DNF documentation][dnf-docs]: official DNF user and reference documentation.
* [Fedora documentation: Package management][fedora-docs]: Fedora's guide to DNF and package management.
* [RHEL documentation: Managing software with DNF][rhel-docs]: Red Hat's guide for RHEL 8+.
* For installing a compatible system from scratch, see [How do I install Rocky Linux?][rocky-install].

## References

* [DNF documentation][dnf-docs]: DNF user and reference documentation.
* [Fedora documentation: Package management][fedora-docs]: Fedora's DNF and package management.
* [RHEL documentation: Managing software with DNF][rhel-docs]: RHEL 8+ package management with DNF.

[dnf-docs]: https://dnf.readthedocs.io/
[fedora-docs]: https://docs.fedoraproject.org/en-US/quick-docs/dnf/
[rhel-docs]: https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/8/html/managing_software_with_the_dnf_tool/
[rocky-install]: {{< ref "blog/how-x/how-do-i-install-rocky-linux" >}}