Skip to content

rpm Command Cheat Sheet

rpm (Red Hat Package Manager) is the low-level package manager for RHEL, CentOS, Fedora, openSUSE, and SLES. High-level tools like yum and dnf build upon rpm to handle dependencies.


Synopsis

rpm [OPTION...]

Modes of Operation

  • Query (-q): Ask questions about installed packages.
  • Install (-i): Install a new package.
  • Upgrade (-U): Upgrade or install.
  • Erase (-e): Remove a package.
  • Verify (-V): Check if files have changed since installation.

1. Querying Packages (-q)

List All Installed Packages (-a)

rpm -qa
# Output:
# bash-4.4.19-10.el8.x86_64
# kernel-4.18.0-147.el8.x86_64

Check if a Package is Installed

rpm -q httpd
# Output: httpd-2.4.37-21.module+el8.2.0+5008+cca404a1.x86_64
# Or: "package httpd is not installed"

Find Which Package Owns a File (-f)

You found a file /etc/passwd and want to know where it came from.

rpm -qf /etc/passwd
# Output: setup-2.12.2-2.el8.noarch

Info About a Package (-i)

rpm -qi bash
Shows URL, License, Description, Build Date.

List Files in a Package (-l)

rpm -ql nginx
Shows every file the package installed.

List Config Files Only (-c)

rpm -qc nginx

List Documentation Only (-d)

rpm -qd nginx

Check Scripts (-s)

Show state of files (normal, not installed, replaced).

rpm -qs nginx

Query a Package File (Not Installed) (-p)

If you have a .rpm file on disk and want to see what's inside.

# Info
rpm -qip package.rpm

# List files
rpm -qpl package.rpm

# Check scripts (pre/post install)
rpm -qp --scripts package.rpm

2. Installing & Upgrading

Note: rpm does not resolve dependencies. Use dnf or yum for that.

Install a Package (-i)

Usage rpm -ivh (Install, Verbose, Hash progress bar).

sudo rpm -ivh package.rpm

Upgrade a Package (-U)

Installs if not present, upgrades if older version exists.

sudo rpm -Uvh package.rpm

Freshen (-F)

Only upgrade if the package is already installed. Do nothing if it's not.

sudo rpm -Fvh package.rpm

Force Install (--force)

Dangerous. Overwrites matches.

sudo rpm -ivh --force package.rpm

Ignore Dependencies (--nodeps)

Extremely Dangerous. Installs even if libraries are missing. The program likely won't run.

sudo rpm -ivh --nodeps package.rpm

3. Removing Packages (-e)

Erase (Uninstall).

sudo rpm -e package_name
(Do not use the full filename .rpm, just the package name).


4. Verifying Packages (-V)

Checks if files on disk match the rpm database (MD5, permissions, size).

rpm -V httpd
Output Codes: - S: Size differs - M: Mode (permissions) differs - 5: MD5 sum differs (File content changed) - D: Device major/minor number mismatch - L: ReadLink path mismatch - U: User ownership differs - G: Group file ownership differs - T: MTime differs

Example:

S.5....T.  c /etc/httpd/conf/httpd.conf
(Size, MD5, and Time changed. It's a Config file).


5. Database Maintainance

If the RPM database gets corrupted.

sudo rpm --rebuilddb

RPM vs DNF/YUM

Feature RPM DNF / YUM
Level Low-level High-level
Dependencies Fails if missing Auto-downloads & installs
Repos No concept of repos Manages repositories
Use Case Querying local files Installing software

Notes

  • Extract content without installing: rpm2cpio package.rpm | cpio -idmv.