RPM is a default open source package management utility for installing, updating, uninstalling, querying and verifying software packages on Linux based operating systems. RPM stands for Red Hat Package Manager which keeps the information of all the installed packages under /var/lib/rpm database. It is mostly used in RHEL, CentOS and Fedora.
RPM has five basic modes of operation which includes:
Install: It is used to install RPM package.
Uninstall: It is used to remove or uninstall RPM package.
Upgrade: It is used to update the existing RPM package.
Verify: It is used to query about different RPM packages.
Query: It is used for the verification of any RPM package.
Each software package consists of an archive of files along with information about the package like its name, version, and a description,
Sources From Where you can find and download RPM packages
Below are the list of sites where you can find and download all RPM packages.
http://www.rpmfind.net/
www.redhat.com/
http://freshrpms.net/
http://rpm.pbone.net/
1. To install a RPM package, use the following command:
# rpm -ivh foo-1.0-2.i386.rpm
Preparing... ############################## [100%]
1:foo ############################## [100%]
Structure of the package includes the following:
- File of names like foo-1.0-2.i386.rpm
- Package name - foo
- Version - 1.0
- Release - 2
- Architecture - i386
2. To remove an installed RPM package, use RPM with -e option
After uninstallation, you can query using rpm -qa to verify the uninstallation
# rpm -ev foo
Notice that we used the package name “foo”, not the name of the original package file “foo-
1.0-2.i386.rpm”.
3. To query a particular RPM package, use this command with -q option
This command will print the package name, version, and release number of the installed package foo. Use this command to verify that a package is or is not installed on your system.
# rpm -q foo
foo-2.3-8
To Query all RPM packages using rpm -qa
# rpm -qa
This command will list all the installed packages on your system. To filter particular package you can combine this with grep command.
# rpm -qa | grep BitTorrent
4. To upgrade a RPM package, use with -Uvh option
With this command, RPM automatically uninstalls the old version of installed package for example foo and installs the new version. Always use rpm -Uvh to install packages, since it works fine even when there are no previous versions of the package installed.
# rpm -Uvh foo-1.0-2.i386.rpm
foo ##################################################
5. To display package information, use the command
This command displays package information; includes name, version and description of the
installed program. Use this command to get information about the installed package.
# rpm -qi foo
Name : foo Relocations: none
Version : 2.3 Vendor: OpenNA.com, Inc.
Release : 8 Build Date: Thu 24 Aug 2000 11:16:53 AM EDT
Install date: Mon 12 Feb 2001 01:17:24 AM EST Build Host: openna.com
Group : Applications/Archiving Source RPM: foo-2.3-8.src.rpm
Size : 271467 License: distributable
Packager : OpenNA.com, Inc. <http://www.openna.com/>
Summary : Here will appears summary of the package.
Description : Here will appears the description of the package.
6. To display package information before installing the program
This command displays package information before installing on your system which includes name, version, and description of the program. Use this command to get information about a package before you install it on your system. For example, the following option -qip (query info package) will print the information of a package.
# rpm -qpi foo-2.3-8.i386.rpm
Name : foo Relocations: none
Version : 2.3 Vendor: OpenNA.com, Inc.
Release : 8 Build Date: Thu 24 Aug 2000 11:16:53 AM EDT
Install date: Mon 12 Feb 2001 01:17:24 AM EST Build Host: openna.com
Group : Applications/Archiving Source RPM: foo-2.3-8.src.rpm
Size : 271467 License: distributable
Packager : OpenNA.com, Inc. <http://www.openna.com/>
Summary : Here will appears summary of the package.
Description : Here will appears the description of the package.
7. To check dependencies of RPM Package before Installation
To view the list of packages on which this package depends you can use rpm -qpR command. This command will display the list of all packages on which installing package depends before installing or upgrading a package. This is the best way to do a dependency check before installing or upgrading a package.
# rpm -qpR <package_name>
# rpm -qpR BitTorrent-5.2.2-1-Python2.4.noarch.rpm
/usr/bin/python2.4
python >= 2.3
python(abi) = 2.4
python-crypto >= 2.0
python-psyco
python-twisted >= 2.0
python-zopeinterface
rpmlib(CompressedFileNames) = 2.6
RPM command and options
-q : Query a package
-p : List capabilities this package provides.
-R: List capabilities on which this package depends.
8. To list files in a installed RPM package, use the command
This command will list all files in a installed RPM package. It works only when the package is
already installed on your system.
# rpm -ql foo
/usr/bin/foo
/usr/bin/foo1
/usr/sbin/foo2
9. To Query documentation of Installed RPM Package
To get the list of available documentation of an installed package, use the following command with option -qdf (query document file). This command will display the location of all manual pages related to package. Here, for example vmstat.
# rpm -qdf /usr/bin/vmstat
/usr/share/doc/procps-3.2.8/BUGS
/usr/share/doc/procps-3.2.8/COPYING
/usr/share/doc/procps-3.2.8/COPYING.LIB
/usr/share/doc/procps-3.2.8/FAQ
/usr/share/doc/procps-3.2.8/NEWS
/usr/share/doc/procps-3.2.8/TODO
10. To list files in package that is not already installed, use the command
This command will list all files in a RPM package that is not already installed on your system. It is useful when you want to know which components are included in the package before installing it.
# rpm -qpl foo
/usr/lib/foo
/usr/bin/foo1
/usr/sbin/foo2
11. To know which files is part of which package, use the command
# rpm -qf /etc/passwd
setup-2.3.4-1
This command will show you from which RPM package the file comes from. It works only when the package is already installed on your system and it is very useful when you see some files into Linux that you do not and want to get detailed information about it.
12. To check a RPM signature package, use the command
# rpm --checksig foo
- This command checks the PGP signature of specified package to ensure its integrity and origin.
- Always use this command first before installing new RPM package on your system.
- GnuPG or PGPsoftware must be already installed on your system before you can use this command.
13. To examine only the md5sum of the package, use the command
# rpm --checksig --nogpg foo
14. To Rebuild corrupted RPM database
Sometimes RPM database gets corrupted, in that situation you need to rebuild corrupted RPM database. In order to recover from a corrupted RPM database you can use the following command:
First of all remove /var/lib/rpm/__db* files to avoid stale locks and then rebuild rpm using below command:
# cd /var/lib
# rm __db*
Rebuild RPM database:
# rpm --rebuilddb
# rpmdb_verify Packages
15. How to List Recently Installed RPM Packages
Use the following rpm command with -qa (query all) option, this will list all the recently installed rpm packages on your system.
# rpm -qa --last
Some Facts about RPM (RedHat Package Manager) RPM is free and released under GPL (General Public License). RPM keeps the information of all the installed packages under /var/lib/rpm database. RPM is the only way to install packages under Linux systems, if you’ve installed packages using source code, then rpm won’t manage it. RPM deals with .rpm files, which contains the actual information about the packages such as: what it is, from where it comes, dependencies info, version info etc.
16. How to List all Imported RPM GPG keys
To print all the imported GPG keys in your system, use the following command.
# rpm -qa gpg-pubkey
gpg-pubkey-58f96f56-467e919a
gpg-pubkey-6b8d79e6-3f49413d
gpg-pubkey-849c449f-4cb9ff31
gpg-pubkey-5680b795-4bd22941
gpg-pubkey-7fac5991-461576f7
gpg-pubkey-0f2672c8-4cd925ee
gpg-pubkey-c106b9de-4e0fd3a3
17. How to Import an RPM GPG key
To verify RHEL/CentOS/Fedora packages, you must import the GPG key. To do so, execute the following command. It will import CentOS 6 GPG key.
# rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
Additional resources to learn more about rpm.
rpm --help : This command displays a quick reference of RPM parameters.
man rpm : The RPM man page gives more detail about RPM parameters than the rpm --help command.
Useful Websites
The RPM website —
http://www.rpm.org/