Overview
The rpm command is a low-level tool used to install, uninstall, update, and query packages on Red Hat-based distributions (such as RHEL, CentOS, AlmaLinux, and Rocky Linux).
While most users now use dnf or yum for automatic dependency resolution, the rpm command remains essential for installing individual .rpm files in offline environments or for performing detailed inspections of installed packages.
Specifications (Arguments and Options)
Syntax
rpm [mode] [options] [package_name or filename]
Main Modes and Options
| Mode/Option | Description |
| -i (Install) | Installs a new package. |
| -U (Upgrade) | Upgrades a package (installs it if it is not already present). |
| -F (Freshen) | Upgrades a package only if it is already installed. |
| -e (Erase) | Uninstalls (removes) a package. |
| -q (Query) | Queries or searches for package information. |
| -V (Verify) | Verifies the status of installed files. |
| -v (Verbose) | Displays detailed information. |
| -h (Hash) | Shows progress with hash marks (#). |
| –test | Performs a dry run without making actual changes. |
| –import | Imports a GPG public key for package signature verification. |
Basic Usage
To install a local .rpm file (e.g., custom-tool-1.0.0.x86_64.rpm), use the -ivh combination. This stands for install, verbose, and hash (progress bar).
# Install a package
sudo rpm -ivh custom-tool-1.0.0.x86_64.rpm
Example output:
Verifying... ################################# [100%]
Preparing... ################################# [100%]
Updating / installing...
1:custom-tool-1.0.0-1.el9 ################################# [100%]
Practical Commands
Test Installation Without Changes
Use the --test option to check for missing dependencies or conflicts before actually installing. If no errors appear, the installation is safe to proceed.
# Installation test (Dry run; no changes made to the system)
rpm -ivh --test new-editor-2.5.rpm
Update Only Existing Packages in a Directory
To update only the software already installed on your system using new .rpm files, use the -F (Freshen) mode. This will not install any new software.
# Update only installed packages using files in the updates directory
sudo rpm -Fvh /mnt/media/updates/*.rpm
Search Within Installed Packages
You can list all installed packages and filter them for a specific name, such as “python.”
# Search for a package name in the list of all installed packages (-a)
rpm -qa | grep python
Identify Which Package a File Belongs To
This command helps you find which RPM package installed a specific file or command on your system.
# Check which package owns /usr/bin/vim
rpm -qf /usr/bin/vim
Example output:
vim-enhanced-8.2.2637-20.el9.x86_64
Verify Package Integrity
This compares the files installed on your system with the metadata in the original .rpm package to check for unauthorized changes or corruption. If there is no output, the package is intact.
# Verify MD5 checksums, file sizes, and other attributes
rpm -Vp custom-tool-1.0.0.x86_64.rpm
Uninstall a Package
To remove a package, specify the package name. Note that the .rpm extension is not used here.
# Remove a package
sudo rpm -e custom-tool
Customization Tips
- Ignore Dependencies (–nodeps): Use this if you must force an installation or removal despite missing dependencies. This is generally discouraged as it can break system consistency.Bash
rpm -ivh --nodeps middleware-lib.rpm - Import GPG Keys (–import): When using packages from third-party repositories, add their public keys to your trust list to prevent tampering.Bash
sudo rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-9
Important Notes
- No Automatic Dependency Resolution: Unlike
dnf, therpmcommand will not download or install required libraries automatically. If you see a “Failed dependencies” error, you must manually install the required packages or usednf. - Naming Conventions: Use the “filename” (e.g.,
pkg.rpm) for installation (-i) or file verification (-p). Use the “package name” (e.g.,pkg) for removal (-e) or querying (-q). - Sudo Privileges: You need root privileges for all operations except for querying (
-q).
Advanced Usage
Display Detailed Information and File Lists
You can check a package’s description, version, build date, and a list of all files it places in the system.
# Display detailed information (i) of a package
rpm -qi httpd
# List all files (l) contained in a package
rpm -ql httpd
Summary
The rpm command is the foundational tool for package management in the Red Hat ecosystem.
While dnf is preferred for daily updates, understanding rpm is vital for troubleshooting, auditing files, and managing systems in environments without internet access. Master these basic commands to improve your server administration and system configuration skills.
