Daily Linux Command: Rpm

<span>rpm</span> is a command-line tool used to manage RPM (Red Hat Package Manager) software packages in Red Hat-based Linux distributions (such as CentOS, RHEL, Fedora). It can be used for operations such as installing, upgrading, querying, verifying, and removing RPM packages.

๐Ÿงพ Basic Syntax:

rpm [options] [package file or name]

โœ… Common Usage Examples:

1. Install an RPM package

sudo rpm -ivh package.rpm
  • <span>-i</span>: Install
  • <span>-v</span>: Verbose output
  • <span>-h</span>: Show installation progress

2. Upgrade an RPM package

sudo rpm -Uvh package.rpm
  • <span>-U</span>: Upgrade, installs if not already installed

3. Remove an installed RPM package

sudo rpm -e package_name
  • <span>-e</span>: Erase

Example:<span>sudo rpm -e httpd</span>

4. Query all installed RPM packages

rpm -qa
  • <span>-q</span>: Query
  • <span>-a</span>: All installed packages

Can be combined with <span>grep</span> to filter specific packages:

rpm -qa | grep httpd

5. Check if a specific RPM package is installed

rpm -q package_name

Example:

rpm -q httpd

Example output:

httpd-2.4.6-97.el7.centos.x86_64

6. Query information about an RPM package (without installing)

rpm -qpi package.rpm
  • <span>-p</span>: For package files that are not yet installed
  • <span>-i</span>: Show package information

7. List files included in an RPM package

rpm -qpl package.rpm
  • <span>-l</span>: List files

8. List files of an installed package

rpm -ql package_name

9. Verify the integrity of an RPM package

rpm -V package_name
  • <span>-V</span>: Verify

Output explanation:

  • <span>S</span> File size differs
  • <span>M</span> Permissions/user/group differ
  • <span>5</span> MD5 checksum differs
  • <span>D</span> Device major/minor number differs
  • <span>L</span> Symbolic link path differs
  • <span>U</span> User differs
  • <span>G</span> Group differs
  • <span>T</span> Modification time differs

10. Force installation (ignore dependencies or conflicts)

sudo rpm -ivh --nodeps package.rpm

โš ๏ธ Warning: Using <span>--nodeps</span> is not recommended as it may lead to system instability.

๐Ÿ› ๏ธ Common Options Summary

Option Description
<span>-i</span> Install package
<span>-v</span> Show verbose output
<span>-h</span> Show progress bar
<span>-U</span> Upgrade package
<span>-e</span> Erase package
<span>-q</span> Query installed packages
<span>-a</span> All installed packages
<span>-p</span> Operate on RPM files (not installed)
<span>-l</span> List files in package
<span>-i</span> View package information
<span>-V</span> Verify package
<span>--nodeps</span> Ignore dependencies

๐Ÿ“Œ Notes

  • <span>rpm</span> does not automatically resolve dependencies; it is recommended to use <span>yum</span> or <span>dnf</span> to manage packages (e.g., <span>yum install package.rpm</span>).
  • If you need to install an RPM package but are missing dependencies, it is advisable to resolve the dependencies first using <span>yum</span> or <span>dnf</span>.

๐Ÿ“š Example: Comprehensive Use of rpm

# List files of a specific package
rpm -ql httpd

# Query information about a package
rpm -qi httpd

# Install a package
sudo rpm -ivh httpd-2.4.6-97.el7.centos.x86_64.rpm

# Upgrade a package
sudo rpm -Uvh httpd-2.4.6-100.el7.centos.x86_64.rpm

# Remove a package
sudo rpm -e httpd

Leave a Comment