
On Linux you rarely download a program from a website and run an installer. You ask a package manager to fetch it from a trusted repository, check its signature, install its dependencies and keep it updated. On RHEL, AlmaLinux, Rocky Linux and Fedora that tool is dnf, and the packages it handles are .rpm files. This guide covers the commands you will use every week: search, install, update, remove, roll back, add repositories such as EPEL, and query what is installed with rpm. Examples are for RHEL 9 and its clones.
Packages, repositories and the tools
- A package is an archive (
.rpm) holding programs, configuration files and metadata such as its version and what it depends on. - A repository is a web location that holds many packages plus an index.
dnfreads those indexes to find what you ask for. dnfis the high-level tool: it resolves dependencies, downloads from repositories and keeps a history.rpmis the low-level tool that installs or inspects individual package files and the local database, without fetching anything or resolving dependencies.yumstill works on RHEL 9, but it is only a link todnf. Usednfin new notes and scripts.
Debian and Ubuntu use apt and .deb files. The ideas are the same, only the commands differ.
Finding packages
dnf search nginx # search names and descriptions
dnf info nginx # version, size, repository, description
dnf list available 'php*' # list matching packages you could install
dnf list installed # everything installed
dnf provides /usr/bin/dig # which package gives me this file?
dnf provides '*/nmap' # search by file name anywhere
dnf provides is the answer to “I got command not found, which package do I need?”. For example, dig comes from bind-utils, and ifconfig from net-tools.
Installing packages
sudo dnf install nginx # install and resolve dependencies
sudo dnf install -y git curl wget # several at once, answer yes automatically
sudo dnf install ./vendor-tool.rpm # a local .rpm file, with dependencies from the repos
sudo dnf reinstall nginx # put the package files back as shipped
Before it installs anything, dnf shows a transaction summary: what it will install, what extra packages it pulls in and the download size. Read that list. The first time you use a repository it also asks you to accept its GPG key, which is how packages are proven to come from the publisher.
Prefer dnf install ./file.rpm over rpm -i file.rpm for a downloaded package. rpm -i will not fetch missing dependencies and simply fails.
Updating the system
sudo dnf check-update # what updates are waiting (does not change anything)
sudo dnf upgrade # install all updates (update is the same command)
sudo dnf upgrade nginx # update just one package
sudo dnf upgrade --security # only security fixes
dnf updateinfo list security # list the security advisories that apply
Update regularly, and reboot when the kernel or core libraries change. To find out whether a reboot is needed:
sudo dnf install -y dnf-utils
sudo needs-restarting -r # says whether a reboot is required
sudo needs-restarting -s # lists services that should be restarted
For unattended servers, the dnf-automatic package can download and apply updates on a timer. Start with “download only” or security-only updates, and watch a few cycles before you let it install everything on a production machine.
Removing packages
sudo dnf remove nginx # remove a package
sudo dnf autoremove # remove dependencies nobody needs any more
sudo dnf clean all # clear cached downloads and metadata
Read the removal list carefully. dnf removes everything that depends on the package, and on a server that can be more than you expect. It refuses to remove protected packages that the system needs, which is a useful safety net.
Undoing a change with dnf history
Every dnf action is recorded as a numbered transaction. That is a real undo button:
$ sudo dnf history
ID | Command line | Date and time | Action(s) | Altered
8 | upgrade | 2026-11-17 09:02 | Upgrade | 14
7 | install nginx | 2026-11-16 18:40 | Install | 3
sudo dnf history info 8 # exactly what transaction 8 changed
sudo dnf history undo 8 # reverse transaction 8
sudo dnf history rollback 7 # return to the state after transaction 7
Undo works only if the old package versions are still available in a repository, so it is best for recent changes. For critical servers, take a snapshot or backup before big upgrades.
Groups and modules
dnf group list # package groups
sudo dnf group install "Development Tools" # compiler, make, and friends
dnf module list nodejs # module streams (alternate versions)
sudo dnf module enable nodejs:20 # choose a stream, then install normally
sudo dnf install nodejs
A group installs a bundle of related packages. A module stream lets one repository offer several versions of a product, such as different Node.js or PHP releases. Enable the stream first, then install.
Repositories: adding EPEL and others
The base repositories (BaseOS and AppStream) contain what Red Hat ships. A lot of useful software lives in EPEL (Extra Packages for Enterprise Linux), a community repository.
dnf repolist # enabled repositories
dnf repolist all # including disabled ones
sudo dnf install epel-release # enable EPEL (AlmaLinux and Rocky)
sudo dnf config-manager --set-enabled crb # CodeReady Builder, needed by some EPEL packages
sudo dnf makecache # refresh the repository indexes
On RHEL itself, EPEL comes from the Fedora project’s release package and crb may need to be enabled with subscription-manager. The AlmaLinux and Rocky commands above are simpler. dnf config-manager comes from the dnf-plugins-core package.
Repository definitions are small text files in /etc/yum.repos.d/:
[example]
name=Example repository
baseurl=https://repo.example.com/el9/x86_64/
enabled=1
gpgcheck=1
gpgkey=https://repo.example.com/RPM-GPG-KEY-example
Keep gpgcheck=1. It makes dnf verify each package signature. Only add repositories from vendors you trust, because a repository can ship software that runs as root.
To switch a repository off for one command only, use --disablerepo (sudo dnf install --disablerepo=epel somepkg). To hold one package at its current version, use the versionlock plugin:
sudo dnf install python3-dnf-plugin-versionlock
sudo dnf versionlock add nginx
sudo dnf versionlock list
sudo dnf versionlock delete nginx
Asking rpm about installed packages
rpm queries the local database. These queries are fast and need no network:
rpm -qa | grep -i kernel # all installed packages, filtered
rpm -qi bash # package information
rpm -ql bash # every file the package installed
rpm -qc openssh-server # only its configuration files
rpm -qf /usr/bin/ls # which package owns this file?
rpm -V openssh-server # verify: which files changed since install?
rpm -K package.rpm # check a downloaded file's signature and digest
$ rpm -qf /usr/bin/ls
coreutils-8.32-36.el9.x86_64
rpm -V is a lightweight integrity check. A line such as S.5....T. c /etc/ssh/sshd_config means the size, checksum and time of a configuration file changed, which is normal for config files you edited, but suspicious for a program file.
Kernels and disk space
By default dnf keeps the latest three kernels (installonly_limit=3 in /etc/dnf/dnf.conf) so you can boot an older one if a new one misbehaves. If /boot is filling up, list and trim them:
rpm -q kernel # installed kernels
uname -r # the one you are running
sudo dnf remove --oldinstallonly # remove old kernels, keeping the newest ones
If the root filesystem is the problem, see how to find what is using disk space on Linux.
Common errors and what they mean
| Message | Usual cause | What to do |
|---|---|---|
No match for argument: name |
Wrong name, or the repository that has it is not enabled | dnf search or dnf provides; enable EPEL or CRB if it is an extra package |
Failed to download metadata for repo |
No network or DNS, wrong repo URL, or a repository that has been retired | Test with curl -I on the baseurl; fix or disable the repo; dnf clean all |
GPG check FAILED or public key is not installed |
Repository key missing or wrong | Import the vendor’s key with rpm --import URL from the vendor’s own page; never turn off gpgcheck as a shortcut |
Problem: conflicting requests or package ... requires |
Two packages that cannot coexist, or a missing dependency | Read the full text. Try --allowerasing only after checking what it would remove |
Waiting for process with pid ... to finish |
Another dnf run (or an automatic update) holds the lock |
Wait for it. Do not delete lock files while the other process is running |
Curl error (6) or Could not resolve host |
DNS problem | See DNS troubleshooting with dig and nslookup |
Quick reference
| Task | Command |
|---|---|
| Find a package | dnf search word |
| Which package has this command or file? | dnf provides /usr/bin/name |
| Install | sudo dnf install package |
| Update everything | sudo dnf upgrade |
| Remove | sudo dnf remove package |
| Undo the last change | sudo dnf history undo last |
| Which package owns a file? | rpm -qf /path/to/file |
| Files a package installed | rpm -ql package |
| Is a reboot needed? | sudo needs-restarting -r |
The Linux commands cheat sheet lists more everyday commands, and after installing a service you can start it with the steps in systemd basics.
Frequently asked questions
What is the difference between dnf and rpm?
dnf downloads packages from repositories and resolves dependencies. rpm works on single package files and the local package database and does not resolve dependencies. Use dnf to install and update, and rpm to query and verify.
Is yum still used on RHEL 9?
The command still exists, but it is a link to dnf kept for compatibility. Everything you type with yum is handled by dnf.
What is EPEL and is it safe?
EPEL is a community repository of extra packages built for RHEL-compatible systems, maintained by the Fedora project. It is widely used and generally considered safe. It is not covered by Red Hat support, so check your support requirements before adding it to a supported production server.
How do I downgrade a package?
Use sudo dnf downgrade package to go back one version, or sudo dnf history undo ID to reverse a whole transaction. Both need the older version to be available in an enabled repository.
Why does dnf say nothing provides a package I need?
The repository that contains it is probably not enabled. Search with dnf provides, then enable the right repository (EPEL, CRB or a vendor repo) and run sudo dnf makecache.
More tutorials like this
Linux Permission Denied Error: Causes and How to Fix It (chmod, namei, id)
Fix the Linux Permission denied error: read ls -l, namei -l and id, then add only the permission letter you need with chmod. Real…
systemd Basics: Manage Services and Read Logs with systemctl and journalctl
Start, stop and enable services with systemctl, read logs with journalctl, write your own service and timer, and troubleshoot a service that will not…
Bash Scripting for Beginners: Variables, Loops, Functions and Exit Codes
Learn Bash scripting from your first script to a safe backup script: variables, quoting, loops, functions, exit codes and set -euo pipefail, with real…


