20 Practical Examples of RPM Commands in Linux
20 Practical Examples of RPM Commands in Linux
by Ravi Saive | Published: April 10, 2013 | Last Updated: January 9, 2018
RPM (Red Hat Package Manager) is an default open source and most popular package
management utility for Red Hat based systems like (RHEL, CentOS and Fedora). The tool
allows system administrators and users to install, update, uninstall, query, verify and
manage system software packages in Unix/Linux operating systems. The RPM formerly
known as .rpm file, that includes compiled software programs and libraries needed by the
packages. This utility only works with packages that built on .rpm format.
This article provides some useful 20 RPM command examples that might be helpful to you.
With the help of these rpm command you can managed to install, update, remove packages in
your Linux systems.
Please remember you must be root user when installing packages in Linux, with the root
privileges you can manage rpm commands with their appropriate options.
Always check the PGP signature of packages before installing them on your Linux systems
and make sure its integrity and origin is OK. Use the following command with –checksig
(check signature) option to check the signature of a package called pidgin.
For installing an rpm software package, use the following command with -i option. For
example, to install an rpm package called pidgin-2.7.9-5.el6.2.i686.rpm.
[root@tecmint]# rpm -ivh pidgin-2.7.9-5.el6.2.i686.rpm
Preparing... ########################################### [100%]
1:pidgin ########################################### [100%]
1. -i : install a package
2. -v : verbose for a nicer display
3. -h: print hash marks as the package archive is unpacked.
Let’s say you would like to do a dependency check before installing or upgrading a package.
For example, use the following command to check the dependencies of BitTorrent-5.2.2-1-
Python2.4.noarch.rpm package. It will display the list of dependencies of package.
1. -q : Query a package
2. -p : List capabilities this package provides.
3. -R: List capabilities on which this package depends..
If you know that all needed packages are already installed and RPM is just being stupid, you
can ignore those dependencies by using the option –nodeps (no dependencies check) before
installing the package.
The above command forcefully install rpm package by ignoring dependencies errors, but if
those dependency files are missing, then the program will not work at all, until you install
them.
Using -q option with package name, will show whether an rpm installed or not.
To view all the files of an installed rpm packages, use the -ql (query list) with rpm command.
Use the following rpm command with -qa (query all) option, will list all the recently installed
rpm packages.
Type the following command to print the all the names of installed packages on your Linux
system.
If we want to upgrade any RPM package “–U” (upgrade) option will be used. One of the
major advantages of using this option is that it will not only upgrade the latest version of any
package, but it will also maintain the backup of the older package so that in case if the newer
upgraded package does not run the previously installed package can be used again.
To un-install an RPM package, for example we use the package name nx, not the original
package name nx-3.5.0-2.el6.centos.i686.rpm. The -e (erase) option is used to remove
package.
[root@tecmint]# rpm -evv nx
The –nodeps (Do not check dependencies) option forcefully remove the rpm package from
the system. But keep in mind removing particular package may break other working
applications.
Let’s say, you have list of files and you would like to find out which package belongs to these
files. For example, the following command with -qf (query file) option will show you a file
/usr/bin/htpasswd is own by package httpd-tools-2.2.15-15.el6.centos.1.i686.
Let’s say you have installed an rpm package and want to know the information about the
package. The following -qi (query info) option will print the available information of the
installed package.
You have download a package from the internet and want to know the information of a
package before installing. For example, the following option -qip (query info package) will
print the information of a package sqlbuddy.
To get the list of available documentation of an installed package, use the following command
with option -qdf (query document file) will display the manual pages related to vmstat
package.
Verifying a package compares information of installed files of the package against the rpm
database. The -Vp (verify package) is used to verify a package.
Type the following command to verify all the installed rpm packages.
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.
To print all the imported GPG keys in your system, use the following command.
Sometimes rpm database gets corrupted and stops all the functionality of rpm and other
applications on the system. So, at the time we need to rebuild the rpm database and restore it
with the help of following command.
[root@tecmint]# cd /var/lib
[root@tecmint]# rm __db*
[root@tecmint]# rpm --rebuilddb
[root@tecmint]# rpmdb_verify Packages