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,
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
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
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 ##################################################
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.
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.
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
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
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
# 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.
# 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.
# rpm --checksig --nogpg foo
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
# 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.
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
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/