All About RPM Utility

RPM stands for Redhat Package Manager. It is a utility that is used to install, uninstall, update, query, and verify software packages in UNIX-like operating systems. RPM was primarily intended for Linux distributions such as Redhat, Suse, CentOS, Fedora, etc. A .rpm package contains compiled programs and library files.

NOTES:

  • RPM utility can only work with .rpm files/packages.
  • RPM won’t be able to manage softwares which are installed using source code.
  • RPM utility does not resolve dependencies.
  • Database for packages installed using RPM utility are stored under directory /var/lib/rpm
  • Only root user or user with sudo root privileges can install .rpm packages using RPM utility.

Operating system used in the example: CentOS Linux release 7.4.1708 (Core)

  1. How to list down installed packages on system?
# rpm -qa
postfix-2.10.1-6.el7.x86_64
centos-release-7-4.1708.el7.centos.x86_64
irqbalance-1.0.7-10.el7.x86_64
setup-2.8.71-7.el7.noarch
microcode_ctl-2.1-22.el7.x86_64
basesystem-10.0-7.el7.centos.noarch
rsyslog-8.24.0-12.el7.x86_64
bind-license-9.9.4-50.el7.noarch
dracut-config-rescue-033-502.el7.x86_64
firewalld-filesystem-0.4.4.4-6.el7.noarch
iprutils-2.4.14.1-1.el7.x86_64
glibc-common-2.17-196.el7.x86_64
  1. Get total number of packages installed on the sytem:
# rpm -qa|wc -l
349
  1. How to install .rpm package?
# rpm -ivh tree-1.6.0-10.el7.x86_64.rpm
  Preparing...
 ################################# [100%]
  Updating / installing...
  1:tree-1.6.0-10.el7
 ################################# [100%]

Here, i: Install v: Print verbose information h: Print 50 hash marks as the package archive is unpacked.

  1. How to remove/erase .rpm package?
# rpm -evh tree-1.6.0-10.el7.x86_64
 Preparing... ################################# [100%]
 Cleaning up / removing...
1:tree-1.6.0-10.el7 ################################# [100%]
  1. How to list down all files included in .rpm package?
# rpm -ql tree
/usr/bin/tree
/usr/share/doc/tree-1.6.0
/usr/share/doc/tree-1.6.0/LICENSE
/usr/share/doc/tree-1.6.0/README
/usr/share/man/man1/tree.1.gz

NOTE: Make sure the .rpm package is installed already.

  1. How to determine package name based on command or file?
# which tree
/bin/tree
# rpm -qf /bin/tree
tree-1.6.0-10.el7.x86_64
# rpm -qf /usr/share/doc/tree-1.6.0
tree-1.6.0-10.el7.x86_64
  1. How to get detailed information for a .rpm package?
# rpm -qi tree
  Name : tree
  Version : 1.6.0
  Release : 10.el7
  Architecture: x86_64
  Install Date: Tue 26 Sep 2017 04:06:27 PM IST
  Group : Applications/File
  Size : 89505
  License : GPLv2+
  Signature : RSA/SHA256, Fri 04 Jul 2014
 11:06:46 AM IST, Key ID 24c6a8a7f4a80eb5
  Source RPM : tree-1.6.0-10.el7.src.rpm
  Build Date : Tue 10 Jun 2014 12:58:53 AM IST
  Build Host : worker1.bsys.centos.org
  Relocations : (not relocatable)
  Packager : CentOS BuildSystem <http: bugs.centos.org="">
  Vendor : CentOS
  URL :
 http://mama.indstate.edu/users/ice/tree/
  Summary : File system tree viewer
  Description :
  The tree utility recursively displays the contents of directories in a tree-like format. Tree is basically a UNIX port of the DOS tree utility.</http:>
  1. How to get details of package based on rpm file?
# rpm -qip tree-1.6.0-10.el7.x86_64.rpm
Name : tree
Version : 1.6.0
Release : 10.el7
Architecture: x86_64
Install Date: (not installed)
Group : Applications/File
Size : 89505
License : GPLv2+
Signature : RSA/SHA256, Fri 04 Jul 2014 11:06:46 AM IST, Key ID 24c6a8a7f4a80eb5
Source RPM : tree-1.6.0-10.el7.src.rpm
Build Date : Tue 10 Jun 2014 12:58:53 AM IST
Build Host : worker1.bsys.centos.org
Relocations : (not relocatable)
Packager : CentOS BuildSystem <http: bugs.centos.org="">
Vendor : CentOS
URL : http://mama.indstate.edu/users/ice/tree/
Summary : File system tree viewer
Description : The tree utility recursively displays the contents of directories in a tree-like format. Tree is basically a UNIX port of the DOS tree utility.</http:>
  1. How to check the date when the .rpm package was installed?
# rpm -qa --last|grep -i tree
tree-1.6.0-10.el7.x86_64 Tue 26 Sep 2017 04:06:27 PM IST
  1. How to get the dates for all installed packages?
# rpm -qa --last |more
  tree-1.6.0-10.el7.x86_64 Tue 26 Sep 2017 04:06:27 PM IST
  unzip-6.0-16.el7.x86_64 Sat 23 Sep 2017 07:10:18 PM IST
  php-pdo-5.4.16-42.el7.x86_64 Sat 23 Sep 2017 06:57:49 PM IST
  php-mysql-5.4.16-42.el7.x86_64 Sat 23 Sep 2017 06:57:49 PM IST
  php-5.4.16-42.el7.x86_64 Sat 23 Sep 2017 06:56:26 PM IST
  php-common-5.4.16-42.el7.x86_64 Sat 23 Sep 2017 06:56:25 PM IST
  1. List down only configuration files associated with a package:
# rpm -qc httpd
/etc/httpd/conf.d/autoindex.conf
/etc/httpd/conf.d/userdir.conf
/etc/httpd/conf.d/welcome.conf
  1. List down dependencies for a .rpm package:
# rpm -qpR bind-utils-9.9.4-51.el7.x86_64.rpm
bind-libs = 32:9.9.4-51.el7
libGeoIP.so.1()(64bit)
libbind9.so.90()(64bit)
libc.so.6()(64bit)

Here, R : List capabilities on which this package depends.

Source: man rpm