RPM stands for Red Hat Package Manager. RPM keeps the information of all the installed packages under /var/lib/rpm database. In this document lets go through some of the important rpm commands which make our life easier.

1. Get the list of installed packages

# rpm -qa

where q – Query
a – All

[root@server ~]# rpm -qa
pygobject2-2.20.0-5.el6.x86_64
foomatic-db-filesystem-4.0-7.20091126.el6.noarch
rhn-client-tools-1.0.0-61.el6.noarch
xml-common-0.6.3-32.el6.noarch
libtasn1-2.3-3.el6.x86_64
tzdata-2011g-1.el6.noarch
libvisual-0.4.0-9.1.el6.x86_64
ncurses-libs-5.7-3.20090208.el6.x86_64
………………………………..
………………..

2. Query a particular rpm package

[root@server ~]# rpm -q crash
crash-5.1.1-2.el6.x86_64

3. Get the details of an installed rpm

# rpm -qi <package>

[root@server ~]# rpm -qi crash
Name        : crash                        Relocations: (not relocatable)
Version     : 5.1.1                             Vendor: CentOS
Release     : 2.el6                         Build Date: Mon 18 Jul 2011 11:49:36 PM EDT
Install Date: Wed 19 Feb 2014 03:51:41 PM EST      Build Host: c6b5.bsys.dev.centos.org
Group       : Development/Debuggers         Source RPM: crash-5.1.1-2.el6.src.rpm
Size        : 5804855                          License: GPLv3
Signature   : RSA/SHA1, Mon 26 Sep 2011 12:17:20 AM EDT, Key ID 0946fca2c105b9de
Packager    : CentOS BuildSystem <http://bugs.centos.org>
URL         : http://people.redhat.com/anderson
Summary     : Kernel crash and live system analysis utility
Description :
The core analysis suite is a self-contained tool that can be used to
investigate either live systems, kernel core dumps created from the
netdump, diskdump and kdump packages from Red Hat Linux, the mcore kernel patch
offered by Mission Critical Linux, or the LKCD kernel patch.

4. Get the details of an rpm before installing it

# rpm -qip <package>
where -i : view information about an rpm
-p : specify a package name

[root@server src]# rpm -qip crash-5.1.1-2.el6.x86_64.rpm
Name        : crash                        Relocations: (not relocatable)
Version     : 5.1.1                             Vendor: CentOS
Release     : 2.el6                         Build Date: Mon 18 Jul 2011 11:49:36 PM EDT
Install Date: (not installed)               Build Host: c6b5.bsys.dev.centos.org
Group       : Development/Debuggers         Source RPM: crash-5.1.1-2.el6.src.rpm
Size        : 5804855                          License: GPLv3
Signature   : RSA/SHA1, Mon 26 Sep 2011 12:17:20 AM EDT, Key ID 0946fca2c105b9de
Packager    : CentOS BuildSystem <http://bugs.centos.org>
URL         : http://people.redhat.com/anderson
Summary     : Kernel crash and live system analysis utility
Description :
The core analysis suite is a self-contained tool that can be used to
investigate either live systems, kernel core dumps created from the
netdump, diskdump and kdump packages from Red Hat Linux, the mcore kernel patch
offered by Mission Critical Linux, or the LKCD kernel patch.

5. To check in which rpm the file belongs to

# rpm -qf <filename>
where f – file name

[root@server ~]# rpm -qf /etc/my.cnf
mysql-libs-5.1.52-1.el6_0.1.x86_64

6. Install a package

# rpm -ivh <package>

where -i : install a package
-v : verbose
-h : print hash marks as the package archive is unpacked.

root@server src]# rpm -ivh ftp-0.17-51.1.el6.x86_64.rpm
Preparing…                ########################################### [100%]
1:ftp                    ########################################### [100%]

7. List all the files in a rpm

#rpm -qlp <package>
where q : query the rpm file
l : list the files in the package
p : specify the package name

[root@server src]# rpm -qlp ftp-0.17-51.1.el6.x86_64.rpm
/usr/bin/ftp
/usr/bin/pftp
/usr/share/man/man1/ftp.1.gz
/usr/share/man/man1/pftp.1.gz
/usr/share/man/man5/netrc.5.gz

8. List the dependancy of a package

#rpm -qRp <package>

[root@server src]# rpm -qRp ftp-0.17-51.1.el6.x86_64.rpm
libc.so.6()(64bit)
libc.so.6(GLIBC_2.11)(64bit)
libc.so.6(GLIBC_2.2.5)(64bit)
libc.so.6(GLIBC_2.3)(64bit)
libc.so.6(GLIBC_2.3.4)(64bit)
libc.so.6(GLIBC_2.4)(64bit)
libncurses.so.5()(64bit)
libreadline.so.6()(64bit)
rpmlib(CompressedFileNames) <= 3.0.4-1
rpmlib(FileDigests) <= 4.6.0-1
rpmlib(PayloadFilesHavePrefix) <= 4.0-1
rtld(GNU_HASH)
rpmlib(PayloadIsXz) <= 5.2-1

9. Get the list of files associated with a package.

[root@server src]# rpm -qlp ftp-0.17-51.1.el6.x86_64.rpm
/usr/bin/ftp
/usr/bin/pftp
/usr/share/man/man1/ftp.1.gz
/usr/share/man/man1/pftp.1.gz
/usr/share/man/man5/netrc.5.gz

10. Upgrading a RPM Package

[root@server src]# rpm -Uvh ftp-0.17-51.1.el6.x86_64.rpm
Preparing…                ########################################### [100%]
1:ftp                    ########################################### [100%]

11. Uninstalling a RPM Package

[root@server src]# rpm -ev  ftp

12. List Recently Installed RPM Packages

[root@server src]# rpm -qa –last | more
ftp-0.17-51.1.el6                             Thu 20 Feb 2014 02:20:21 PM EST
crash-5.1.1-2.el6                             Thu 20 Feb 2014 02:20:16 PM EST
python-ethtool-0.6-5.el6                      Wed 19 Feb 2014 03:23:54 PM EST
python-dmidecode-3.10.13-3.el6_4              Wed 19 Feb 2014 03:23:54 PM EST
m2crypto-0.20.2-9.el6                         Wed 19 Feb 2014 03:23:54 PM EST
libxml2-python-2.7.6-14.el6                   Wed 19 Feb 2014 03:23:54 PM EST

13. Remove a package without dependency

[root@server src]# rpm -ev –nodeps ftp

14. Query documentation of Installed RPM Package

[root@server src]# rpm -qdf /usr/bin/find
/usr/share/doc/findutils-4.4.2/AUTHORS
/usr/share/doc/findutils-4.4.2/COPYING
/usr/share/doc/findutils-4.4.2/NEWS
/usr/share/doc/findutils-4.4.2/README
/usr/share/doc/findutils-4.4.2/THANKS
/usr/share/doc/findutils-4.4.2/TODO
/usr/share/info/find-maint.info.gz
/usr/share/info/find.info.gz
/usr/share/man/man1/find.1.gz
/usr/share/man/man1/xargs.1.gz

15. Verify a RPM Packages installed

[root@server src]# rpm -Vp wget-1.12-1.4.el6.x86_64.rpm
…….T.  c /etc/wgetrc
..5….T.    /usr/bin/wget
…….T.  d /usr/share/doc/wget-1.12/NEWS
…….T.  d /usr/share/doc/wget-1.12/README
…….T.  d /usr/share/doc/wget-1.12/sample.wgetrc
…….T.  d /usr/share/info/wget.info.gz
…….T.    /usr/share/locale/be/LC_MESSAGES/wget.mo
…….T.    /usr/share/locale/bg/LC_MESSAGES/wget.mo
…….T.    /usr/share/locale/ca/LC_MESSAGES/wget.mo
…….T.    /usr/share/locale/cs/LC_MESSAGES/wget.mo
…….T.    /usr/share/locale/da/LC_MESSAGES/wget.mo
…….T.    /usr/share/locale/de/LC_MESSAGES/wget.mo
…….T.    /usr/share/locale/el/LC_MESSAGES/wget.mo
…….T.    /usr/share/locale/en@boldquot/LC_MESSAGES/wget.mo
…….T.    /usr/share/locale/en@quot/LC_MESSAGES/wget.mo

16. Verify all the RPM packages installed

[root@server src]# rpm -Va | more
.M….G..    /usr/sbin/rhn-profile-sync
S.5….T.  c /etc/login.defs
.M…….    /usr/bin/chage
.M…….    /usr/bin/gpasswd
.M…….    /usr/bin/newgrp
…..UG..    /opt/zimbra/altermime-0.3.10
…..UG..    /opt/zimbra/altermime-0.3.10/LICENSE
…..UG..    /opt/zimbra/altermime-0.3.10/bin
…..UG..    /opt/zimbra/altermime-0.3.10/bin/altermime
…..UG..    /opt/zimbra/amavisd-new-2.8.0
…..UG..    /opt/zimbra/amavisd-new-2.8.0/.spamassassin
…..UG..    /opt/zimbra/amavisd-new-2.8.0/.spamassassin/init
…..UG..    /opt/zimbra/amavisd-new-2.8.0/.spamassassin/init/bayes_seen
…..UG..    /opt/zimbra/amavisd-new-2.8.0/.spamassassin/init/bayes_toks
…..UG..    /opt/zimbra/amavisd-new-2.8.0/DB_CONFIG.amavisd
…..UG..    /opt/zimbra/amavisd-new-2.8.0/sbin
…..UG..    /opt/zimbra/amavisd-new-2.8.0/sbin/amavisd

17. Rebuild a corrupted RPM Database

[root@server src]# cd /var/lib/rpm
[root@server src]# rm __db*
[root@server src]# rpm –rebuilddb

18. List the documentation of installed rpm

[root@server rpm]# rpm -qd httpd
/usr/share/doc/httpd-2.2.15/ABOUT_APACHE
/usr/share/doc/httpd-2.2.15/CHANGES
/usr/share/doc/httpd-2.2.15/LICENSE
/usr/share/doc/httpd-2.2.15/NOTICE
/usr/share/doc/httpd-2.2.15/README
/usr/share/doc/httpd-2.2.15/VERSIONING
/usr/share/man/man8/apachectl.8.gz
/usr/share/man/man8/htcacheclean.8.gz
/usr/share/man/man8/httpd.8.gz
/usr/share/man/man8/rotatelogs.8.gz
/usr/share/man/man8/suexec.8.gz

19. Checking the integrity of a RPM package

root@server src]# rpm -K ftp-0.17-51.1.el6.x86_64.rpm
ftp-0.17-51.1.el6.x86_64.rpm: rsa sha1 (md5) pgp md5 OK

20. Test a Package Installation

If you want to test the package installation without actually installing the package,
then you can achieve this by using ‘–test’ option.

[root@server src]# rpm -ivh –test crash-5.1.1-2.el6.x86_64.rpm
Preparing…                ########################################### [100%]
[root@server src]#
[root@server src]# rpm -qi crash
package crash is not installed

21. Force the installation

In case of some dependency issues, rpm wont allow the package installation. If we want to proceed with the installation neglecting the dependencies, use –force option. You can repair an package by providing ‘-U’ option along with ‘–force’.

[root@server]# rpm -Uvh –force tftp-server-0.42-3.1.i386.rpm
warning: tftp-server-0.42-3.1.i386.rpm: Header V3 DSA signature: NOKEY, key ID 37017186
Preparing…                ########################################### [100%]
1:tftp-server            ########################################### [100%]

[root@server ]# rpm -V tftp-server