The RPM command in Linux installs, updates, removes, queries, and verifies software packages that use the RPM Package Manager format. It works by reading metadata stored inside package files to ensure dependencies and file locations are respected during operations. You use it when managing software on Red Hat-based systems like Fedora, CentOS, or RHEL.

How RPM Handles Package Files

RPM packages are standalone archives that include compiled programs, configuration files, scripts, and a metadata header. The metadata tells RPM what other packages the software needs (dependencies), which directories it writes to, and what version it is. When you run a command like rpm -i package.rpm, RPM checks the header first, validates signatures if enabled, then extracts files to their correct locations. It also records the installation in its internal database so it knows what is installed and where. This database lives in /var/lib/rpm and is updated automatically on every install, upgrade, or erase operation.

What Happens During an Install

During installation, RPM first verifies the package file itself. If signature checking is turned on, it confirms the package came from a trusted source using GPG keys you have imported. Next, it checks for missing dependencies by comparing the package’s requirements against what is already installed. If a required package is absent, RPM stops and reports the missing item. Then it runs any pre-install scripts included in the package, extracts files to their target paths, sets file permissions and ownership, and finally runs post-install scripts. If any step fails, RPM rolls back the changes and leaves the system unchanged.

Common Package Operations

There are five main actions you perform with RPM: install, upgrade, erase, query, and verify. Each uses a different flag: -i for install, -U for upgrade (replaces an older version), -e for erase (remove), -q for query (get info), and -V for verify (check file integrity). You can combine flags with options like -v for verbose output or -h for hash marks showing progress. For example, to install a local file, you type rpm -i mysoftware-1.2.3.rpm. To upgrade it later, rpm -U mysoftware-2.0.0.rpm replaces the older version cleanly.

Querying Installed Packages

Querying is useful for checking what is installed and where. You can ask for a specific package name, list all installed packages, or find which package owns a particular file. For instance, rpm -q httpd tells you if Apache is installed and its version. rpm -qa lists everything, which you can pipe to grep to narrow results: rpm -qa | grep perl shows all Perl-related packages. To see which package installed a file like /etc/httpd/conf/httpd.conf, you run rpm -qf /etc/httpd/conf/httpd.conf. This helps you track down the source of a configuration file or binary.

Where People Go Wrong

Many users try to install RPM packages on systems that use a different package manager, like Debian’s DEB format or Arch’s AUR, and expect RPM to work. RPM files are not portable across distributions unless the underlying system is RPM-based. Another frequent error is ignoring dependency errors: forcing an install with --nodeps skips checks and often leads to broken software later because required libraries or tools are missing. Also, installing from untrusted sources without verifying GPG signatures risks running tampered code. Always confirm the package comes from a known repository or has a valid signature before installing.

Missing Dependencies and Workarounds

RPM does not automatically fetch missing packages from the internet; that is handled by higher-level tools like yum or dnf. If rpm -i fails with a dependency error, you must either install the missing packages manually using rpm or switch to dnf/yum which resolves dependencies automatically. Using --force or --nodeps should be a last resort and only after you understand the risks. For example, if a package requires libssl.so.10 but your system has libssl.so.1.1, forcing the install may break other software that relies on the newer library.

Verifying Installed Files

Verification checks that files match what was originally installed by comparing checksums, sizes, permissions, and ownership against the database. Run rpm -V package-name to see any changes. The output uses a series of letters and dots, each position meaning something specific: S means file size differs, M means permissions or ownership changed, 5 means the checksum (MD5) does not match, D means device attributes differ, L means a symbolic link target changed, and T means modification time is different. A dot means that check passed. For example, S.5...... means the size and checksum changed but permissions and time are correct. If you see unexpected changes, especially in system-critical files, investigate further before making changes.

What a Verify Output Looks Like

When you run rpm -V bash, you might see something like S.5....... which tells you the bash binary’s size and checksum differ from what RPM expects. That could indicate corruption, a manual edit, or an incomplete upgrade. If you see many changes across many packages, it may point to a broader issue like disk errors or a failed update. In such cases, re-installing the affected packages often fixes the problem. Always run verification on a clean system first to know what normal looks like.

Where RPM Fits in the Ecosystem

RPM is low-level software management. Modern Red Hat-based systems use dnf (or yum on older versions) as the front-end, which calls RPM internally but adds features like automatic dependency resolution and internet-based package downloads. You still need RPM directly for tasks dnf cannot handle, like installing a local .rpm file without adding a repository, or querying the package database when network tools are unavailable. Knowing both tools gives you flexibility: use dnf for routine installs and updates, and RPM for fine-grained control or troubleshooting.

When to Avoid RPM

Do not use RPM to manage software on non-RPM systems like Ubuntu or openSUSE Leap (which switched to zypper but still supports RPM files). Even on RPM systems, avoid mixing package sources: installing a third-party RPM alongside distribution packages can cause conflicts if both try to own the same file paths. If you must use external RPMs, prefer those built for your exact distribution and version. Check the package metadata first with rpm -qpi package.rpm to see its requirements and description before installing.