rpm : 25 practical common examples of rpm command

If you are a user of a Linux distro that uses the rpm to manage its packages like red hat (RHEL)SUSEopenSUSECentOSFedoraMageiaScientific LinuxKorora Project ..etc. You indeed should know the essential uses of rpm.

RPM Package Manager (RPM) (originally Red Hat Package Manager; now a recursive acronym) is a package management system.[5] The name RPM refers to the following: the .rpm file format, files in the .rpm file format, software packaged in such files, and the package manager program itself. RPM was intended primarily for Linux distributions; the file format is the baseline package format of the Linux Standard Base. Source

1. Install an “.rpm” package:

Short syntax: $ rpm -ivh PKG.rpm
Long syntax: $ rpm --install -v --hash PKG.rpm

$ rpm -ivh htop.rpm

2. Upgrade / Install an “.rpm” package:

Short syntax: $ rpm -Uvh PKG.rpm
Long syntax: $ rpm --upgrade -v --hash PKG.rpm

$ rpm -Uvh htop.rpm
It will upgrade the package if it was installed. Otherwise it will install a fresh copy of it.

3. Downgrade / Revert an rpm package to an older version:

Short syntax: $ rpm -Uvh --oldpackage PKG.rpm
Long syntax: $ rpm --upgrade -v --hash --oldpackage PKG.rpm

$ rpm -Uvh --oldpackage htop.rpm

4. Remove / Erase an installed package:

Short syntax: $ rpm -ev PKG
Long syntax: $ rpm --erase -v PKG

$ rpm -ev htop

5. Remove / Erase an installed package without checking dependencies:

Short syntax: $ rpm -ev --nodeps PKG
Long syntax: $ rpm --erase -v --nodeps PKG

$ rpm -ev --nodeps htop
Remove an installed package and don’t check dependencies before uninstalling the packages.

6. List all installed packages:

Short syntax: $ rpm -qa
Long syntax: $ dpkg --query --all

$ rpm -qa | less

7. List individual installed package(s):

Short syntax: $ rpm -q PKG
Long syntax: $ dpkg --query PKG

$ rpm -q coreutils
$ rpm -q coreutils perl

Or, add the option -a to be able to use the REGEX.

$ rpm -qa 'lib*'
$ rpm -qa | grep -iE 'coreutils|perl'

8. List all of last recently installed packages:

Short syntax: $ rpm -qa --last
Long syntax: $ rpm --query --all --last

$ rpm -qa --last | less

9. List all files in a package:

Short syntax: $ rpm -ql PKG
Long syntax: $ rpm --query --list PKG

$ rpm -ql tmux
It will list all files in the given package. If you want to print the name of the package before each printed file, use --filesbypkg instead of --list. (i.e: $ rpm -q --filesbypkg tmux).

10. Find out which package does a particular file belong to:

Short syntax: $ rpm -qf FILE
Long syntax: $ rpm --query --file FILE

$ rpm -qf /usr/bin/md5sum
Find out what package owns a particular file.

11. List configuration files of a package:

Short syntax: $ rpm -qc PKG
Long syntax: $ rpm --query --configfiles PKG

$ rpm -qc ranger

12. List configuration files of a command:

Short syntax: $ rpm -qcf PKG
Long syntax: $ rpm --query --configfiles --file PKG

$ rpm -qcf /usr/bin/sha1sum

13. Display info / details about an installed package:

Short syntax: $ rpm -qi PKG
Long syntax: $ rpm --query --info PKG

$ rpm -qi coreutils

14. Display info / details about an rpm package before installing it:

Short syntax: $ rpm -qpi PKG.rpm
Long syntax: $ rpm --query --package --info PKG.rpm

$ rpm -qi tmux.rpm

15. Display all of an installed package’s dependencies:

Short syntax: $ rpm -qR PKG
Long syntax: $ rpm --query --requires PKG

$ rpm -qR htop

16. Display all of an rpm package’s dependencies:

Short syntax: $ rpm -qpR PKG.rpm
Long syntax: $ rpm --query --package --requires PKG.rpm

$ rpm -qpR htop.rpm

17. Check rpm package’s signature:

Long syntax: $ rpm --checksig PKG.rpm

$ rpm --checksig htop.rpm

18. Verify an installed package against an rpm package:

Short syntax: $ rpm -Vp PKG.rpm
Long syntax: $ rpm --verify --package PKG.rpm

$ rpm -Vp htop.rpm

Output meaning:

  • S file Size differs.
  • M Mode differs (includes permissions and file type).
  • 5 MD5 sum differs.
  • D Device major/minor number mismatch.
  • L readlink(2) path mismatch.
  • U User ownership differs.
  • G Group ownership differs.
  • T mTime differs.

19. Verify all rpm packages:

Short syntax: $ rpm -Va
Long syntax: $ rpm --verify --all

$ rpm -Va

20. Rebuild corrupted rpm database:

$ cd /var/lib
$ mkdir rpmdb.bkp
$ mv __db* rpmdb.bkp/
$ rpm --rebuilddb
$ rpmdb_verify Packages

21. Find out the state of an installed rpm package:

Short syntax: $ rpm -qs PKG
Long syntax: $ rpm --query --state PKG

$ rpm -qs htop
Display the states of files in the package (implies -l). The state of each file is one of normal, not installed, or replaced.

22. Find out the state of an rpm package:

Short syntax: $ rpm -qsp PKG.rpm
Long syntax: $ rpm --query --state --package PKG.rpm

$ rpm -qsp htop.rpm

23. Locate the documentations:

Short syntax: $ rpm -qd PKG
Long syntax: $ rpm --query --docfiles PKG

Of an installed rpm package:

$ rpm -qd htop

Of an rpm package file: (By using: -p or --package)

$ rpm -qdp htop.rpm

Of an rpm package that owns a file:  (By using: -f or --file)

$ rpm -qdf /usr/bin/shred

24. Import an rpm GPG key:

Long syntax: $ rpm --import GPG-PUBKEY-FILE

25. List all imported rpm GPG keys:

Short syntax: $ rpm -qa gpg-pubkey*
Long syntax: $ rpm --query --all gpg-pubkey*

To get more help:

See the manual:

$ man rpm

Or read it online: rpm(8)

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.