# rpm — The Low-Level RPM Package Tool

> Practical guide to rpm — the low-level package tool for Red Hat systems: query, install, verify and manage individual RPM packages.

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

<!-- PROSE:intro -->
rpm is the low-level tool that sits underneath package managers like dnf and zypper: it installs, removes, and queries individual local `.rpm` packages on Red Hat-based systems such as Fedora, RHEL, or openSUSE. Unlike dnf, however, rpm does not resolve dependencies – if a required library is missing, the installation simply fails. For everyday work you are better off with dnf; rpm is the right choice when you want to query a single package precisely, inspect an RPM file before installing it, or examine an installed package in detail. This guide walks you through the commands you reach for most: installing, querying, and verifying.
<!-- PROSE:intro:end -->

## Install & Remove

`rpm -ivh <file>.rpm` — Install an RPM package (verbose + progress bar).

```bash
sudo rpm -ivh package.rpm
```

`rpm -Uvh <file>.rpm` — Upgrade a package (install if not present).

```bash
sudo rpm -Uvh package-2.0.rpm
```

`rpm -Fvh <file>.rpm` — Freshen: upgrade only if an older version is installed.

```bash
sudo rpm -Fvh package-2.0.rpm
```

`rpm -e <package>` — Remove (erase) an installed package.

```bash
sudo rpm -e nginx
```

`rpm -e --nodeps <package>` — Remove a package ignoring dependencies.

```bash
sudo rpm -e --nodeps libfoo
```

## Query Installed Packages

`rpm -qa` — List all installed packages.

```bash
rpm -qa
```

`rpm -qa | grep <pattern>` — Search for installed packages.

```bash
rpm -qa | grep php
```

`rpm -qi <package>` — Show detailed info about an installed package.

```bash
rpm -qi nginx
```

`rpm -ql <package>` — List all files installed by a package.

```bash
rpm -ql nginx
```

`rpm -qc <package>` — List only config files of a package.

```bash
rpm -qc nginx
```

`rpm -qd <package>` — List only documentation files of a package.

```bash
rpm -qd nginx
```

`rpm -qR <package>` — List dependencies of a package.

```bash
rpm -qR nginx
```

`rpm -qf <file>` — Find which package owns a file.

```bash
rpm -qf /usr/sbin/nginx
```

## Query RPM Files

`rpm -qip <file>.rpm` — Show info about an uninstalled RPM file.

```bash
rpm -qip package.rpm
```

`rpm -qlp <file>.rpm` — List files inside an RPM file.

```bash
rpm -qlp package.rpm
```

`rpm -qRp <file>.rpm` — Show dependencies of an RPM file.

```bash
rpm -qRp package.rpm
```

## Verify

`rpm -V <package>` — Verify installed files against the package database.

```bash
rpm -V nginx
```

`rpm -Va` — Verify all installed packages.

```bash
rpm -Va
```

`rpm -K <file>.rpm` — Check the signature and integrity of an RPM file.

```bash
rpm -K package.rpm
```

`rpm --import <key>` — Import a GPG public key for package verification.

```bash
sudo rpm --import https://example.com/RPM-GPG-KEY
```

## Common Patterns

`rpm -qa --last | head -20` — Show the 20 most recently installed/updated packages.

```bash
rpm -qa --last | head -20
```

`rpm -qa --queryformat '%{NAME} %{VERSION}-%{RELEASE}\n'` — Custom formatted package list.

```bash
rpm -qa --queryformat '%{NAME} %{VERSION}-%{RELEASE}\n' | sort
```

`rpm2cpio <file>.rpm | cpio -idmv` — Extract files from an RPM without installing.

```bash
rpm2cpio package.rpm | cpio -idmv
```

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

rpm gives you full, direct control over individual packages – along with the responsibility that comes with it. Because rpm does not resolve dependencies, you should normally use dnf (or zypper on openSUSE) for installing and updating, and reserve rpm for targeted queries, verification, and extracting individual files. Be especially careful with `-e`/`--erase` (it removes packages) and with `--nodeps` and `--force`: they bypass the safety nets and can leave your system in an inconsistent state. Always check downloaded packages before installing with `rpm -K` (GPG signature), and import the source's keys beforehand via `rpm --import`.

## Further Reading

- [rpm.org](https://rpm.org/) – the official project site of the RPM Package Manager
- [RPM documentation (rpm.org)](https://rpm.org/documentation.html) – reference, manuals, and man pages for the package manager
<!-- PROSE:outro:end -->

## Related Commands

- [apk](https://www.jpkc.com/db/en/cheatsheets/package-managers/apk/) – package manager of the Alpine Linux distribution
- [apt](https://www.jpkc.com/db/en/cheatsheets/package-managers/apt/) – high-level package tool for Debian/Ubuntu
- [apt-get](https://www.jpkc.com/db/en/cheatsheets/package-managers/apt-get/) – classic Debian/Ubuntu package tool for scripts

