X

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
Example: 

$ rpm -ivh htop.rpm

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

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

$ 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
Example: 

$ rpm -Uvh --oldpackage htop.rpm

4. Remove / Erase an installed package:

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

$ 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
Example: 

$ 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
Example:

$ rpm -qa | less

7. List individual installed package(s):

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

$ 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
Example: 

$ rpm -qa --last | less

9. List all files in a package:

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

$ 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
Example: 

$ 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
Example: 

$ rpm -qc ranger

12. List configuration files of a command:

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

$ rpm -qcf /usr/bin/sha1sum

13. Display info / details about an installed package:

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

$ 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
Example: 

$ rpm -qpi tmux.rpm

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

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

$ 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
Example: 

$ rpm -qpR htop.rpm

17. Check rpm package’s signature:

Long syntax: $ rpm --checksig PKG.rpm
Example: 

$ 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
Example: 

$ 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
Example: 

$ 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
Example: 

$ 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
Example: 

$ rpm -qsp htop.rpm

23. Locate the documentations:

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

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)

DeaDSouL: A big fan of UNIX & Linux.. Who adores programming..
Related Post