English
RPM Tool Usage Guide: From rpm -ivh to yum Equivalent Operations | Installation, Upgrade, Query, and yum Comparison Practice

1. Introduction
RPM (Red Hat Package Manager) is the basic package management tool in Red Hat family Linux distributions (such as RHEL, CentOS, Fedora). It can directly operate .rpm Package files, to complete operations such as installation, upgrade, query, and uninstallation.
Although modern systems prefer to use yum(or dnf) to manage software packages, but understand rpm Command and its relationship with yum the correspondence is still very important for troubleshooting, offline installation, and scripting.
This article will start from commonly used rpm Start with commands and focus on introducing rpm -ivh,rpm -Uvh and other practices, and provide the corresponding yum Equivalent operation method.
2. rpm Common Commands Quick Reference
2.1 Installation
bash
# Install an RPM package and display detailed information and progress.
rpm -ivh package.rpm
# Parameter description:
# -i, --install install
# -v, --verbose Show detailed information
# -h, --hash Show installation progress (# signs)Note:rpm -ivh Does not automatically resolve dependencies. If a package has unmet dependencies, it will error out and abort.
2.2 Upgrade
bash
# Upgrade an rpm package (install it if not installed)
rpm -Uvh package.rpm
# Parameter description:
# -U, --upgrade Upgrade (if the package is not installed, perform installation)
# -v, --verbose
# -h, --hashbash
# Only upgrade installed packages (if not installed, report an error and do not install)
rpm -Fvh package.rpm
# Parameter description:
# -F, --freshen Only upgrade already installed packages2.3 Query
bash
# Query information about installed packages
rpm -q package_name
# Query the file list of installed packages
rpm -ql package_name
# Find which installed package a file belongs to.
rpm -qf /path/to/file
# Query information about uninstalled RPM packages
rpm -qpi package.rpm
# Query the files contained in an uninstalled RPM package
rpm -qlp package.rpm2.4 Uninstall
bash
# Uninstall installed packages
rpm -e package_name
# Force uninstall (ignore dependency checks, use with caution)
rpm -e --nodeps package_name2.5 Verification and Signature
bash
# Verify the file integrity of installed packages
rpm -V package_name
# Check RPM package signature
rpm --checksig package.rpm3. Comparison of equivalent operations between rpm and yum
yum is an RPM-based package manager that can automatically resolve dependencies. The following table lists rpm Common operations and yum the equivalent command for.
| Operation | rpm command | yum equivalent command | Explanation |
|---|---|---|---|
| Install local RPM package | rpm -ivh package.rpm | yum localinstall package.rpm or yum install ./package.rpm | yum will automatically resolve dependencies |
| Upgrade local RPM package | rpm -Uvh package.rpm | yum localupdate package.rpm or yum update ./package.rpm | yum automatically resolves dependencies. |
| Only upgrade installed packages | rpm -Fvh package.rpm | yum update package_name(From warehouse) | For local packages there is no direct equivalent; you can use yum localupdate |
| Install the package from the repository | Not applicable (download required first) | yum install package_name | Install from configured repository |
| Upgrade the packages in the repository | Not applicable | yum update package_name | Upgrade from repository |
| Uninstall package | rpm -e package_name | yum remove package_name | yum will handle dependencies |
| Query installed package information | rpm -q package_name | yum info installed package_name | similar |
| Query package file list | rpm -ql package_name | yum provides /path/to/file(Reverse) | yum has no direct equivalent, can use repoquery -l |
| Query the package to which the file belongs | rpm -qf /path/to/file | yum provides /path/to/file | Similar |
| List all installed packages | rpm -qa | yum list installed | Similar |
| Clear cache | Not applicable | yum clean all | Only yum |
Prompt:yum localinstall In newer versions, it has been unified as yum install ./package.rpm, just specify the local path directly.
4. Practical Examples
4.1 Installing local packages using rpm
bash
# Download an RPM package (example)
wget https://example.com/packages/nginx-1.20.1-1.el7.x86_64.rpm
# Install using rpm
rpm -ivh nginx-1.20.1-1.el7.x86_64.rpmIf a dependency error occurs, for example:
error: Failed dependencies:
pcre >= 8.32 is needed by nginx-1.20.1-1.el7.x86_64At this point, switch to yum Installation:
bash
yum install ./nginx-1.20.1-1.el7.x86_64.rpmyum Will automatically download and install missing dependencies from the repository.
4.2 Using the rpm upgrade package
bash
# Upgrade (install if not installed)
rpm -Uvh nginx-1.22.0-1.el7.x86_64.rpm
# Upgrade only the installed nginx
rpm -Fvh nginx-1.22.0-1.el7.x86_64.rpmcorresponding yum Operation:
bash
# Upgrade local packages (automatically resolve dependencies)
yum update ./nginx-1.22.0-1.el7.x86_64.rpm4.3 Query and Validation
bash
# Check whether nginx is installed
rpm -q nginx
# List the files installed by nginx.
rpm -ql nginx
# Check which package a configuration file belongs to
rpm -qf /etc/nginx/nginx.conf
# Verify the integrity of the nginx package files
rpm -V nginx4.4 Uninstall
bash
# Uninstall using rpm
rpm -e nginx
# Uninstall using yum (recommended, handles dependencies)
yum remove nginx5. Notes and Best Practices
Prefer using yum/dnf: Unless offline installation, script control, or troubleshooting is required, prefer to use
yum, because it can automatically resolve dependencies.rpm -ivhandrpm -Uvhthe difference:-iInstall only; an error will occur if the package already exists;-UUpgrade or install;-FOnly upgrade installed packages.Avoid
--nodepsand--force: Forced operations may cause confusion in the system package management state; use only when the consequences are clearly understood.Import GPG key: Before installing third-party rpm packages, ensure that a trusted GPG key is imported, use
rpm --importImport.offline environment: Can be used in offline environments
yumdownloaderorrepotrackDownload dependencies in advance, then useyum localinstallInstallation.Query uninstalled packages: Use
rpm -qpi,rpm -qlpYou can view package information and file list before installation.
6. Summary
rpm is the cornerstone of Linux package management, mastering rpm -ivh,rpm -Uvh,rpm -q,rpm -e and other commands, which can help you handle offline installation and troubleshooting with ease. And yum As a higher-level tool, it is more convenient in dependency handling and repository management. Understanding the equivalence between the two allows flexible selection according to the scenario.
I hope this article helps you use RPM and YUM tools better.