Skip to content
Visual explainer 3h 30m to learn 5 steps

dnf, rpm & repositories

Install, update and query packages and configure a custom repository with dnf.

By Invicly Tech, , in Linux Administration (RHCSA-style). About 10 minutes to read.

Topic 11 of 42

In short

On RHEL-family systems, rpm installs and queries individual package files, while dnf resolves dependencies and fetches packages from repositories. Repositories are defined by .repo files and signed with GPG keys so you only install trusted software. dnf history lets you see and undo transactions.

Explained simply

On Linux you rarely download installers from websites. Software comes as packages: archives that hold a program's files plus information about it, such as its version and which other packages it needs. On RHEL, Rocky and Alma these are RPM packages.

rpm is the low-level tool. It installs, removes and inspects one package file at a time, and it keeps a database of everything installed. It does not download anything and does not fetch missing dependencies for you.

dnf is the tool you use every day. It knows about repositories, which are online or local collections of packages. When you type dnf install httpd, dnf finds the package, works out everything else it needs, downloads it all, checks the signatures and hands the files to rpm to install.

Because every package is signed with a GPG key, dnf can prove that a package really comes from Red Hat or from the project you trust, and has not been changed on the way. Keeping those checks switched on is one of the cheapest security wins you have.

Press Play on a diagram to walk through it one step at a time.

LayersRPM software stack
  1. 1
    dnf

    Search, dependency resolution, updates, history.

  2. 2
    Repositories

    .repo files in /etc/yum.repos.d with baseurl and gpgkey.

  3. 3
    rpm

    Installs, queries and verifies individual packages.

  4. 4
    RPM database

    Record of installed packages and their files.

  5. 5
    Files on disk

    Binaries, configs and docs the package installed.

MapAnatomy of a .repo file
/etc/yum.repos.d/internal.repo
  • [internal]
    • Repo ID used in dnf commands
  • name=
    • Human-readable description
  • baseurl= or metalink=
    • Where packages and metadata live
  • enabled=1
    • 0 keeps it defined but unused
  • gpgcheck=1
    • Verify every package signature
  • gpgkey=
    • URL or file:// path of the public key

In depth

What happens during dnf install

First dnf loads metadata for every enabled repository: an index of packages, versions, dependencies and file lists. It keeps it in a cache under /var/cache/dnf and refreshes it when it is older than the metadata_expire setting (48 hours by default, though repos can set their own). dnf makecache or the --refresh option forces a fresh download.

Next the dependency solver finds a set of packages that satisfies your request without conflicts, and shows you the transaction: what will be installed, upgraded or removed. After you confirm, dnf downloads the packages, checks each GPG signature, runs a test transaction and then lets rpm unpack the files and run the package scripts. Finally the rpm database and dnf's history are updated.

Flowdnf install httpd, step by step
  1. 1
    Load repo metadata

    From cache or freshly downloaded

  2. 2
    Solve dependencies

    httpd plus every package it needs

  3. 3
    Show and confirm

    The transaction summary

  4. 4
    Download and verify

    GPG signature checked per package

  5. 5
    rpm installs

    Files unpacked, scripts run

  6. 6
    Record it

    rpm database and dnf history

Answering questions with rpm queries

rpm -q is a fast, offline way to learn about installed software. rpm -qa lists every package, rpm -qi httpd shows version, vendor and description, rpm -ql httpd lists its files, and rpm -qc httpd lists only its configuration files, which is a quick way to find where a service is configured. rpm -qf /usr/sbin/httpd goes the other way and names the package that owns a file. rpm -q --scripts shows what a package runs during install or removal.

Add -p to ask the same about a package file you have not installed yet: rpm -qlp ./tool.rpm. rpm -V httpd verifies installed files against the database and prints a code for each change: S for size, 5 for content, M for mode, U for owner, T for modification time. A c next to the code marks a config file, where changes are expected.

  • rpm -qa --last | head shows the most recently installed packages
  • rpm -Va checks every package; slow but thorough
  • rpm -K file.rpm checks a package file's signature

Repositories, keys and trust

A repository is defined by a section in a .repo file in /etc/yum.repos.d. The section name in brackets is the repo ID. baseurl points at the packages (http, https or file://), or metalink and mirrorlist name a list of mirrors. enabled=1 turns it on. gpgcheck=1 makes dnf check each package's signature, and gpgkey says where the public key is.

The first time a package from a new key is installed, dnf shows the key's fingerprint and asks you to accept it. You can also import keys yourself with rpm --import; imported keys appear as packages named gpg-pubkey, which rpm -qa gpg-pubkey lists. Compare fingerprints with the vendor's website before trusting a key.

dnf config-manager --add-repo URL writes a .repo file for you (it comes from dnf-plugins-core), and --set-enabled or --set-disabled switches repos on and off.

  • dnf repolist -v shows each repo's URL and package count
  • dnf --disablerepo='*' --enablerepo=local install pkg uses one repo only
  • Never leave gpgcheck=0 in place to silence an error

Groups, module streams, history and reboots

Package groups install a whole set at once: dnf group list shows them and dnf group install "Development Tools" installs one. On RHEL 8 and 9, AppStream also offers module streams, which are parallel versions of one stack such as nodejs or postgresql. dnf module list nodejs shows the streams and dnf module enable nodejs:20 picks one before you install.

Every dnf transaction gets a number. dnf history list shows them, dnf history info 12 shows what changed, dnf history undo 12 reverses one transaction and dnf history rollback 12 returns to the state after it. Undo needs the old package versions to still be available in a repo, so it can fail for older upgrades.

After updates, dnf needs-restarting -r (from dnf-utils) tells you whether a reboot is required, for example after a new kernel or glibc.

Learn it in 5 short steps

About 40m each. Track them with a timer in your plan.

  1. 1
    Search, install and remove with dnf~40m
  2. 2
    Query installed packages with rpm -q~40m
  3. 3
    Add a repo file in /etc/yum.repos.d~40m
  4. 4
    Import and verify GPG keys~40m
  5. 5
    Inspect history and roll back~40m

Key points

  • dnf provides */command finds which package ships a command.
  • rpm -qf /path shows which package owns a file; rpm -ql lists a package's files.
  • Keep gpgcheck=1 so packages are verified against the repository key.
  • dnf history undo N reverses a transaction.

Key terms

Tap a card to flip it. 0/5 known

Examples

bash
sudo dnf install -y httpd
dnf provides */semanage
rpm -qf /etc/httpd/conf/httpd.conf
cat <<EOF | sudo tee /etc/yum.repos.d/local.repo
[local]
name=Local repo
baseurl=http://repo.example.com/BaseOS
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release
EOF
dnf repolist && dnf history

Install, find a provider, own a file and add a repository.

Install from a local repository built from the ISO

A lab or exam machine has no internet, but the installation DVD is attached. Step 1: mount the ISO, and add it to /etc/fstab if it must survive a reboot. Step 2: create one repo for BaseOS and one for AppStream, because RHEL 9 media holds both. Step 3: point gpgkey at the release key already on the system (ls /etc/pki/rpm-gpg shows its name on Rocky or Alma). Step 4: check the repos and install something.

bash
sudo mkdir -p /mnt/iso && sudo mount -o ro /dev/sr0 /mnt/iso
sudo tee /etc/yum.repos.d/iso.repo > /dev/null <<'EOF'
[iso-baseos]
name=ISO BaseOS
baseurl=file:///mnt/iso/BaseOS
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release

[iso-appstream]
name=ISO AppStream
baseurl=file:///mnt/iso/AppStream
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release
EOF
sudo dnf repolist && sudo dnf install -y tmux

Undo an update that broke something

After installing a set of PHP packages, a web app stops working. Step 1: find the transaction in dnf history. Step 2: look at exactly what it installed or upgraded. Step 3: undo it, which removes what it added and downgrades what it upgraded, if the old versions are still in a repo. Step 4: check which config files the package owns and whether any changed, so you can tell a package problem from a local edit.

bash
sudo dnf history list | head -5
#  ID | Command line         | Date and time    | Action(s) | Altered
#  14 | install php php-fpm  | 2026-11-09 10:12 | Install   |   12
sudo dnf history info 14
sudo dnf history undo 14
rpm -qc httpd
rpm -V httpd

Quick reference

  • dnf provides '*/semanage' finds the package that ships a command
  • rpm -qc PACKAGE lists only that package's configuration files
  • rpm -qf /path names the package that owns a file
  • rpm -V PACKAGE reports changed files: S size, 5 content, M mode, T time
  • dnf install ./file.rpm installs a local file and fetches its dependencies
  • dnf config-manager --add-repo URL creates a .repo file (needs dnf-plugins-core)
  • dnf history undo ID reverses one transaction
  • dnf needs-restarting -r tells you if a reboot is needed after updates

Common mistakes

  • Setting gpgcheck=0 permanently to silence a key error.
  • Installing a downloaded package with rpm -i and fighting dependencies; use dnf install ./file.rpm.

Quick quiz

Pick an answer to see if you're right and why.

Question 1

1You have a downloaded tool.rpm that needs two other packages. Which command installs it and its dependencies?

Question 2

2Which command lists only the configuration files that the chronyd package installed?

Question 3

3rpm -V httpd prints S.5....T. c /etc/httpd/conf/httpd.conf. What does it mean?

Question 4

4Where are imported RPM signing keys listed?

0/4 answered

Practice exercises

Try each one yourself first. Use the hint if you get stuck, then compare with the solution.

  1. Exercise 1easy

    Find out which package provides the command semanage, install it, and then show which package owns /usr/sbin/semanage.

  2. Exercise 2medium

    Add a repository with ID internal from http://repo.example.com/el9/x86_64, signed with the key at http://repo.example.com/RPM-GPG-KEY-internal. Make sure signatures are checked, and list the repo.

  3. Exercise 3hard

    Install the Development Tools group, then use dnf history to remove exactly what that transaction added, and confirm gcc is gone.

Check yourself

Answer in your head, reveal, then be honest with yourself.

Feel confident about this topic?

Frequently asked questions

What is the difference between yum and dnf?
dnf replaced yum as the package manager on RHEL 8 and later. The yum command still exists there as a link to dnf, so old instructions usually still work.
Is dnf update the same as dnf upgrade?
Yes. dnf update is kept as an alias of dnf upgrade.
How do I list installed packages?
Use dnf list --installed or rpm -qa. Pipe to grep to look for one name, or use rpm -q name for an exact match.
Why does dnf ask me to import a GPG key?
The first package signed by a new key needs that key to be trusted. Check that the fingerprint matches the vendor's published one, then accept it.

Go deeper

ShareXLinkedInWhatsApp