# Use RPM and YUM package management

> Install, upgrade, remove and query RPM packages with rpm, yum/dnf and zypper, check signatures, and find which package owns a file.

Source: https://aminbytes.dev/bytes/installation-and-packages/rpm-and-yum/


Red Hat Enterprise Linux, Fedora, CentOS Stream, AlmaLinux, Rocky Linux, openSUSE and SUSE Linux Enterprise all use **RPM packages**. Just like on Debian, there are two layers, and you need both for the exam:

- **`rpm`** is the low-level tool. It installs, removes, queries and verifies `.rpm` files and keeps the package database. It **doesn't download anything or resolve dependencies**.
- **`yum`** (and its successor **`dnf`**) on the Red Hat family, and **`zypper`** on SUSE, download from repositories, resolve dependencies, and use `rpm` underneath.

Follow along in a container: `docker run -it --rm almalinux:9` (a free RHEL 9 rebuild) or `docker run -it --rm fedora`. You're root there, so drop the `sudo`.

## What an .rpm is

```text
tree-1.8.0-10.el9.x86_64.rpm
 │     │    │   │    └ architecture (x86_64, aarch64, noarch, i686)
 │     │    │   └ distribution tag (el9 = Enterprise Linux 9)
 │     │    └ release of the packaging
 │     └ upstream version
 └ package name
```

A package with `noarch` works on any CPU (scripts, docs). A `.src.rpm` holds source code to rebuild the package. Each package is a compressed archive of files plus a header with metadata, dependencies, install scripts and a digital signature. The database of installed packages lives in **`/var/lib/rpm/`**.

## rpm: install, upgrade, remove

| Command | What it does |
| --- | --- |
| `rpm -ivh file.rpm` | **Install**. Fails if any version is already installed. |
| `rpm -Uvh file.rpm` | **Upgrade**, or install if it isn't there. The usual choice. |
| `rpm -Fvh file.rpm` | **Freshen**: upgrade only if an older version is installed |
| `rpm -e package` | **Erase** (remove) an installed package |
| `rpm --reinstall -vh file.rpm` | Reinstall the same version |

`-v` is verbose and `-h` prints hash marks as a progress bar. Other options you'll see: `--test` (dry run), `--nodeps` (ignore dependencies, risky) and `--force` (overwrite files and versions, risky). Kernels are usually installed with `-i`, not `-U`, so the old kernel stays as a fallback.

```bash
dnf download tree            # get the .rpm file (install dnf-plugins-core if this command is missing)
sudo rpm -Uvh tree-1.8.0-10.el9.x86_64.rpm
```

```text
Verifying...                          ################################# [100%]
Preparing...                          ################################# [100%]
Updating / installing...
   1:tree-1.8.0-10.el9                ################################# [100%]
```

If a dependency is missing, `rpm` just stops with `error: Failed dependencies:` and a list. That's exactly what `dnf` is for.

## rpm: query

Every query starts with `-q`. Add letters for what you want to know:

| Command | Shows |
| --- | --- |
| `rpm -q tree` | Is it installed? Which version? |
| `rpm -qa` | All installed packages (`rpm -qa 'kernel*'` filters, `--last` sorts by install date) |
| `rpm -qi tree` | Info: version, vendor, build date, signature, description |
| `rpm -ql tree` | List of files in the package |
| `rpm -qc tree` / `rpm -qd tree` | Only its config files / documentation |
| `rpm -qf /usr/bin/tree` | Which package owns this file |
| `rpm -qR tree` | What it requires (dependencies) |
| `rpm -q --whatrequires bash` | Which installed packages need this capability |
| `rpm -q --whatprovides libc.so.6` | Which installed package provides a capability |
| `rpm -q --changelog tree` / `--scripts` | Package history / install and removal scripts |
| `rpm -qpi file.rpm`, `rpm -qpl file.rpm` | The same queries on a **package file** (`-p`) instead of the database |

```bash
rpm -qf /usr/bin/tree
rpm -qi tree | head -6
```

```text
tree-1.8.0-10.el9.x86_64
Name        : tree
Version     : 1.8.0
Release     : 10.el9
Architecture: x86_64
Install Date: Tue 01 Dec 2026 10:12:44 AM UTC
Group       : Unspecified
```

## rpm: verify integrity and signatures

`rpm -V` compares installed files against the database. No output means everything matches. `rpm -Va` checks every package on the system.

```bash
sudo rpm -V openssh-server
```

```text
S.5....T.  c /etc/ssh/sshd_config
```

Each position is a test; a dot means it passed:

| Code | Meaning | Code | Meaning |
| --- | --- | --- | --- |
| `S` | Size differs | `L` | Symlink target differs |
| `M` | Mode (permissions or type) differs | `U` | User owner differs |
| `5` | Checksum (digest) differs | `G` | Group owner differs |
| `D` | Device number differs | `T` | Modification time differs |
| `P` | Capabilities differ | `missing` | The file is gone |

The letter before the path is the file type: `c` config, `d` documentation, `l` license, `r` readme. A changed config file is normal; a changed `/usr/bin/` file isn't.

Packages are **signed** with the distribution's GPG key so you know they're genuine and unchanged. The public keys sit in `/etc/pki/rpm-gpg/`:

```bash
sudo rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-AlmaLinux-9   # trust a key
rpm -qa 'gpg-pubkey*'                                         # keys you trust
rpm -K tree-1.8.0-10.el9.x86_64.rpm                           # check a file (same as --checksig)
```

```text
tree-1.8.0-10.el9.x86_64.rpm: digests signatures OK
```

Without the right key imported, you get `digests SIGNATURES NOT OK`.

## rpm2cpio: unpack without installing

Sometimes you want one file out of a package (a default config, a lost binary) without installing it. **`rpm2cpio`** turns an `.rpm` into a `cpio` archive, and `cpio` unpacks it into the current folder:

```bash
mkdir /tmp/x && cd /tmp/x
rpm2cpio ~/tree-1.8.0-10.el9.x86_64.rpm | cpio -idmv
```

```text
./usr/bin/tree
./usr/share/doc/tree/README
./usr/share/licenses/tree/LICENSE
./usr/share/man/man1/tree.1.gz
226 blocks
```

`cpio -i` extracts, `-d` creates folders, `-m` keeps file times, `-v` lists names. Use `cpio -t` instead to only list the contents.

## yum and dnf

**YUM** (Yellowdog Updater, Modified) was the RHEL/CentOS front end up to version 7. **DNF** replaced it in Fedora 22 and RHEL 8. The commands are nearly identical, and on RHEL 8 and 9 `yum` is simply a link to `dnf`, so everything below works with either name. Fedora 41 moved on to **DNF5**, still called with `dnf`.

| Command | What it does |
| --- | --- |
| `yum install tree` | Install with dependencies (`yum install ./file.rpm` for a local file) |
| `yum reinstall tree` | Reinstall the same version |
| `yum remove tree` | Remove (`erase` is an old alias) |
| `yum update` / `yum upgrade` | Upgrade everything, or just the packages you name |
| `yum check-update` | List available updates without installing |
| `yum search word` | Search names and summaries |
| `yum info tree` | Details about a package, installed or not |
| `yum list installed` / `yum list available` | Installed / installable packages |
| `yum provides /usr/bin/dig` | Which package (installed or not) has this file. Also `whatprovides`. |
| `yum repolist` | Enabled repositories |
| `yum history` / `yum history undo 5` | Past transactions, and undoing one |
| `yum clean all` | Delete cached metadata and packages |
| `yum group list` / `yum group install "Development Tools"` | Package groups |
| `yumdownloader tree` / `dnf download tree` | Download the `.rpm` without installing |

```bash
dnf provides /usr/bin/dig
```

```text
bind-utils-32:9.16.23-24.el9_5.x86_64 : Utilities for querying DNS name servers
Repo        : appstream
Matched from:
Filename    : /usr/bin/dig
```

For a file name without a path, use a pattern in quotes: `dnf provides '*/libssl.so.3'`. To see what a package that isn't installed contains, use `dnf repoquery -l tree`; for its dependencies, `dnf repoquery --requires tree`.

## /etc/yum.conf and /etc/yum.repos.d/

The main config is **`/etc/yum.conf`**. With DNF it's `/etc/dnf/dnf.conf`, and on RHEL 8 and 9 `/etc/yum.conf` is a link to it. The `[main]` section holds global settings:

```ini {title="/etc/yum.conf"}
[main]
gpgcheck=1
installonly_limit=3
clean_requirements_on_remove=True
best=True
skip_if_unavailable=False
```

`gpgcheck=1` refuses unsigned packages. `installonly_limit=3` keeps three kernels installed. Old YUM also set `cachedir=/var/cache/yum` and `keepcache` here.

Repositories are defined in **`.repo` files in `/etc/yum.repos.d/`**, one section per repository:

```ini {title="/etc/yum.repos.d/example.repo"}
[example]
name=Example packages for EL $releasever
baseurl=https://repo.example.com/el/$releasever/$basearch/
enabled=1
gpgcheck=1
gpgkey=https://repo.example.com/RPM-GPG-KEY-example
```

`$releasever` (like `9`) and `$basearch` (like `x86_64`) are filled in for you. Instead of `baseurl`, a repo can use `mirrorlist` or `metalink` to pick a mirror. Set `enabled=0` to switch it off, or use one-off flags: `yum --enablerepo=example install foo`, `yum --disablerepo=example update`. `dnf config-manager --add-repo URL` writes a `.repo` file for you.

## zypper (SUSE)

openSUSE and SLES use **zypper**. Most commands have a short form:

| Command | Short | What it does |
| --- | --- | --- |
| `zypper refresh` | `ref` | Refresh repository metadata |
| `zypper install tree` | `in` | Install (`in -f` or `--force` reinstalls) |
| `zypper remove tree` | `rm` | Remove |
| `zypper update` | `up` | Update installed packages |
| `zypper dist-upgrade` | `dup` | Upgrade the whole distribution (openSUSE Tumbleweed, release upgrades) |
| `zypper list-updates` | `lu` | Show available updates |
| `zypper search tree` | `se` | Search (`se -i` for installed only) |
| `zypper info tree` | `if` | Package details |
| `zypper what-provides /usr/bin/tree` | `wp` | Which package has a file or capability (same as `se --provides`) |
| `zypper repos` | `lr` | List repositories |
| `zypper addrepo URL alias` | `ar` | Add a repository (`removerepo`, `rr`, to delete) |

Repository files live in `/etc/zypp/repos.d/`. Try it with `docker run -it --rm opensuse/leap`. Because SUSE packages are RPMs, every `rpm` command above works there too.

> [!TIP]
> Mixing tools is fine for **queries**: `rpm -qf`, `rpm -qi` and `rpm -V` are fast and work on every RPM system. For **installing and removing**, prefer `dnf` or `zypper`, so dependencies stay consistent.

## Exam checklist

- `rpm` handles local files, no dependency resolution. `yum`/`dnf` and `zypper` resolve dependencies from repositories.
- Install `-i`, upgrade `-U`, freshen `-F` (only if installed), erase `-e`, usually with `-vh`. `--reinstall`, `--nodeps`, `--force`, `--test`.
- Queries: `-qa`, `-qi`, `-ql`, `-qc`, `-qd`, `-qf file` (owner), `-qR` (requires), `--whatprovides`, `--whatrequires`, and `-qp...` for a package file.
- Verify with `rpm -V` / `-Va`: `S` size, `M` mode, `5` checksum, `T` time, `c` config file. Check signatures with `rpm -K` / `--checksig`, add keys with `rpm --import`.
- `rpm2cpio file.rpm | cpio -idmv` extracts files without installing.
- `yum`/`dnf`: `install`, `reinstall`, `remove`, `update`, `check-update`, `search`, `info`, `list`, `provides`, `repolist`, `clean all`. `dnf` replaced `yum` (RHEL 8+, Fedora).
- Config: `/etc/yum.conf` (`/etc/dnf/dnf.conf`), repositories as `.repo` files in `/etc/yum.repos.d/` with `baseurl`, `enabled`, `gpgcheck`, `gpgkey`.
- `zypper`: `in`, `rm`, `up`, `dup`, `se`, `if`, `ref`, `lr`, `ar`, `wp`. Repos in `/etc/zypp/repos.d/`.


## Byte check

1. Which `rpm` command upgrades a package **only if** an older version is already installed?
   - `rpm -Uvh pkg.rpm`
   - **`rpm -Fvh pkg.rpm`** (correct)
   - `rpm -ivh pkg.rpm`
   `-F` (freshen) skips packages that aren't installed. `-U` upgrades or installs, and `-i` installs, failing if any version is already there.

2. How do you see the files inside `app.rpm` **without** installing it?
   - `rpm -ql app`
   - **`rpm -qpl app.rpm`** (correct)
   - `rpm -qf app.rpm`
   `-p` makes the query read the package file instead of the database. `rpm -ql app` only works once it's installed, and `-qf` finds the owner of an installed file.

3. `rpm -V openssh-server` prints `S.5....T.  c /etc/ssh/sshd_config`. What happened?
   - The package signature is broken
   - **The config file was changed: size, checksum and time differ** (correct)
   - The file is missing
   Each letter is a failed check: `S` size, `5` checksum, `T` modification time. The `c` marks a config file, so most likely someone edited it on purpose.


