rpm Command Examples in Linux

The rpm command is used to manage RPM packages on Red Hat-derived distributions. It includes many different options, some of which are described in the following table.

Option Used To
-i {package name} Install the specified software.
-e {package name} Erase (uninstall) the package.
-v Enable verbose mode, providing more detail.
-h Print hash marks as a progress bar.
-V {package name} Verify software components of package exist.

Syntax

The syntax of the rpm command is:

# rpm [options] [package name]

Verifying the software components of a package:

rpm command examples in Linux

rpm querying

One of the most powerful features of the RPM package manager is the ability to maintain a database of software information. This database enables administrators to discover package version information, list all installed software, discover dependency information, etc.

Example command queries include the following.

Command Used To
rpm -qa List all installed software (typically a very large output).
rpm -qi {package name} List information about a particular package.
rpm -qc {package name} List the configuration files for a particular package.

Querying information about a package.

Querying information about a package

rpm Verification

RPM can be used to verify software. The verification will check to see if the installed software components match what the RPM package specifies should be installed. The verify option is used when troubleshooting installed software to ensure that the entire software package is installed and valid.

rpm Upgrades

Part of the software lifecycle is to keep software current. RPM offers two primary ways of accomplishing this goal:

  • -U — upgrades the installed package, and installs the package if it is not already installed.
  • -F — freshens the installed package, i.e., upgrades but does not install the package if it is not already installed.

rpm Command Examples

1. To install rpm package:

# rpm -ivh pidgin-2.7.9-5.el6.2.i686.rpm

Preparing...         ########################### [100%]
1:pidgin               ########################### [100%]

2. To List all files of an installed RPM package:

# rpm -ql BitTorrent

3. To List Recently Installed RPM Packages:

# rpm -qa --last

4. To Upgrade a RPM Package:

# rpm -Uvh nx-3.5.0-2.el6.centos.i686.rpm

5. To Remove a RPM Package:

# rpm -evv nx

6. Get the Information of RPM Package Before Installing:

# rpm -qip sqlbuddy-1.3.3-1.noarch.rpm

7. To Import an RPM GPG key:

# rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6

8. To List all Imported RPM GPG keys:

# rpm -qa gpg-pubkey*

9. To see the packages under any group:

# rpm -qg "System Environment/Shells"

10. To check dependencies:

# rpm -qpR BitTorrent-5.2.2-1-Python2.4.noarch.rpm

11. To check an Installed RPM Package:

# rpm -q BitTorrent

12. To Verify a RPM Package:

# rpm -Vp sqlbuddy-1.3.3-1.noarch.rpm

13. To verify all RPM Packages:

# rpm -Va

14. To check all the changed files:

# rpm -q --changelog bash

15. To se most recently installed packages:

# rpm -qa --last | head

16. Getting Information on Package Files:

# rpm -qpc qt-4.6.2-17.fc12.x86_64.rpm

17. Querying Package Files Remotely:

# rpm -qp ftp://username:password@hostname:port/path/to/rpm/file
# rpm -qp http://hostname:port/path/to/rpm/file

18. We can verify the rpm file for its consistency:

# rpm --verify --file /bin/ls
# rpm --verify -p samba-3.4.5....rpm

Following are the list of failure codes:

  • 5 - MD5 checksum
  • S - File size
  • L - Symbolic link
  • T - File modification time
  • D - Device
  • U - User
  • G - Group
  • M - Mode

Always check the PGP signature of packages before installing them on your Linux systems and make sure its integrity and origin is OK.

# rpm --checksig pidgin-2.7.9-5.el6.2.i686.rpm
pidgin-2.7.9-5.el6.2.i686.rpm: rsa sha1 (md5) pgp md5 OK