# dnf — Package Management on Fedora and RHEL

> Practical guide to dnf, the package manager for Fedora, RHEL and CentOS Stream — installing, updating, modules, groups plus history and rollback.

Source: https://www.jpkc.com/db/en/cheatsheets/package-managers/dnf/

<!-- PROSE:intro -->
dnf (Dandified YUM) is the package manager for Fedora, RHEL 8+, CentOS Stream as well as Rocky Linux and AlmaLinux – the successor to the classic yum with faster, cleaner dependency resolution. You use it to install, update and remove software, manage repositories and work with modules and groups to pick whole software stacks or specific version streams on purpose. Its transaction history is especially handy: every action is logged, and `dnf history undo` lets you roll back a botched install or a failed update. This guide walks you through the dnf commands you reach for daily – from updating through modules to rollback.
<!-- PROSE:intro:end -->

## Update & Upgrade

`dnf check-update` — Check for available package updates.

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

`dnf update` — Update all packages (alias for upgrade).

```bash
sudo dnf update -y
```

`dnf upgrade` — Upgrade all installed packages.

```bash
sudo dnf upgrade
```

`dnf upgrade --security` — Install only security updates.

```bash
sudo dnf upgrade --security
```

`dnf upgrade <package>` — Upgrade a specific package.

```bash
sudo dnf upgrade nginx
```

## Install & Remove

`dnf install <package>` — Install a package.

```bash
sudo dnf install nginx
```

`dnf install -y <package>` — Install without confirmation.

```bash
sudo dnf install -y httpd php
```

`dnf install <file>.rpm` — Install a local RPM file (with dependency resolution).

```bash
sudo dnf install ./package.rpm
```

`dnf reinstall <package>` — Reinstall a package.

```bash
sudo dnf reinstall openssh-server
```

`dnf remove <package>` — Remove a package and its unused dependencies.

```bash
sudo dnf remove nginx
```

`dnf autoremove` — Remove unused dependency packages.

```bash
sudo dnf autoremove
```

## Search & Info

`dnf search <query>` — Search for packages by name or summary.

```bash
dnf search nodejs
```

`dnf info <package>` — Show detailed info about a package.

```bash
dnf info nginx
```

`dnf list installed` — List all installed packages.

```bash
dnf list installed
```

`dnf list available` — List all available packages.

```bash
dnf list available | grep php
```

`dnf provides '<file>'` — Find which package provides a file or command.

```bash
dnf provides '*/bin/dig'
```

`dnf repoquery -l <package>` — List files that a package installs.

```bash
dnf repoquery -l nginx
```

`dnf deplist <package>` — Show dependencies of a package.

```bash
dnf deplist nginx
```

## Groups & Modules

`dnf group list` — List available package groups.

```bash
dnf group list
```

`dnf group install '<group>'` — Install a package group.

```bash
sudo dnf group install 'Development Tools'
```

`dnf module list` — List available modules and streams.

```bash
dnf module list
```

`dnf module enable <module>:<stream>` — Enable a module stream.

```bash
sudo dnf module enable nodejs:20
```

`dnf module install <module>:<stream>` — Install a module stream.

```bash
sudo dnf module install php:8.3
```

## Repositories

`dnf repolist` — List enabled repositories.

```bash
dnf repolist
```

`dnf repolist all` — List all repositories (enabled and disabled).

```bash
dnf repolist all
```

`dnf config-manager --add-repo <url>` — Add a new repository.

```bash
sudo dnf config-manager --add-repo https://rpm.example.com/repo.repo
```

`dnf config-manager --set-enabled <repo>` — Enable a disabled repository.

```bash
sudo dnf config-manager --set-enabled crb
```

`dnf config-manager --set-disabled <repo>` — Disable a repository.

```bash
sudo dnf config-manager --set-disabled epel-testing
```

## History & Cleanup

`dnf history` — Show transaction history.

```bash
dnf history
```

`dnf history info <id>` — Show details of a specific transaction.

```bash
dnf history info 15
```

`dnf history undo <id>` — Undo a specific transaction.

```bash
sudo dnf history undo 15
```

`dnf clean all` — Clean all cached data (metadata + packages).

```bash
sudo dnf clean all
```

`dnf makecache` — Rebuild the metadata cache.

```bash
sudo dnf makecache
```

<!-- PROSE:outro -->
## Conclusion

dnf takes the tedious dependency work off your hands and makes maintaining a Fedora or RHEL system clear and reproducible. Treat removing actions like `remove`, `autoremove` and `distro-sync` with care – they can clear out more than you expect, so review the announced package list before you confirm. Modifying commands need `sudo`; if an update ever breaks something, `dnf history undo <id>` is your lifeline to cleanly roll back the last transaction. Only add repositories and GPG keys from sources you trust – third-party repos can slip in arbitrary packages.

## Further Reading

- [dnf documentation](https://dnf.readthedocs.io/) – official reference for commands and options
- [Fedora docs: Managing software with dnf](https://docs.fedoraproject.org/en-US/quick-docs/dnf/) – official introduction to package management
<!-- PROSE:outro:end -->

## Related Commands

- [apk](https://www.jpkc.com/db/en/cheatsheets/package-managers/apk/) – package manager for Alpine Linux, lean and container-friendly
- [apt](https://www.jpkc.com/db/en/cheatsheets/package-managers/apt/) – the high-level package manager for Debian and Ubuntu
- [apt-get](https://www.jpkc.com/db/en/cheatsheets/package-managers/apt-get/) – the classic, script-friendly Debian/Ubuntu tool

