Useful RPM Command With Examples In Linux

In this session, we will focus on some useful RPM command with examples. RPM stands for Red Hat Package Manager which is responsible for installing, verifying, upgrading, querying, and uninstalling packages. With RPM, we can do these five main functions, which are described below: –

Query: Check the system to check the local database and report the total installed packages, whose configuration file is related to the package, for example “/etc/passwd” configuration file, now we can find “password” which is of the .rpm package.
Install: This will allow you to install a fresh package with a .rpm extension.
Erase or uninstall: This will allow you to uninstall already installed packages.
Upgraded: This will allow you to upgrade installed packages from the following version to the above release version without losing customization settings.
Verify: Verify the package before installation.

Useful RPM Command With Examples In Linux
Useful RPM Command With Examples In Linux

The file name, package version, package release date, package description documentation in the RPM package, etc. The RPM database location is /var/lib/rpm where information about the store’s installs, such as file attributes and package revision, etc. RPM is backward support for both commands and other programs like Yum.

Name of the package-Version of the Package-Release.Package Architecture. rpm

Let’s compare the above rpm pattern with the below DHCP .rpm package.

DHCP-3.0.5-23.el5.i386.rpm

  • DHCP    –    Name of the package
  • 3.0.5    –   Version of the Package
  • 23         –   Release
  • el5.i386    –    Architecture

So Let’s have a look at the Useful and Important commands of RPM, I have categorized rpm commands as per their used like Query, Installation, Uninstallation, Up-gradation, and Verification.

1. Query :

Query all Installed rpm Packages:

To query all installed packages in the system use the below command.

Example:

# rpm -qa

Where:

  • q – To query a Package
  • a – Perform task for all

Query Particular rpm Package:

To find a particular package we can use the rpm command with option -q, Here I am querying to find if DHCP package is installed or not.

Example:

# rpm -q dhcp

Query Particular rpm Package using grep

To find a particular package using rpm command with grep as shown below.

Example:

# rpm -qa | grep dhcp
dhcpv6-client-1.0.10-18.el5
dhcp-3.0.5-23.el5

Query the file is belonging to which rpm package

To find out, the file ( e.g. configurations file ) belongs to which rpm package we can use the rpm command with -qf option, Here I am finding /etc/fstab file is belonging to which rpm package as shown below.

Example:

# rpm -qf /etc/fstab 
setup-2.5.58-7.el5

Where:

  • f  – to mention a file name

Also Read : TAR Command Examples in Linux

To list files and directories with its location of an installed rpm package

To list the files and directories with their location installed by the package we can use the rpm command with option -ql as is shown below.

Example:

# rpm -ql dhcp
/etc/dhcpd.conf
/etc/rc.d/init.d/dhcpd
/etc/rc.d/init.d/dhcrelay
/etc/sysconfig/dhcpd
/etc/sysconfig/dhcrelay
/usr/bin/omshell
/usr/sbin/dhcpd
.
.
.
/var/lib/dhcpd
/var/lib/dhcpd/dhcpd.leases

Where:

  • l – To list files and directories

Query the Information of already installed rpm package

Suppose we want to know some information about a package which is already installed, we can do that by using rpm package with -qi option, Example is shown below.

Example:

# rpm -qi nano
Name        : nano                         Relocations: (not relocatable)  
Version     : 1.3.12                            Vendor: Red Hat, Inc.   
Release     : 1.1                           Build Date: Wed 12 Jul 2006 09:58:34 AM PDT
Install Date: Mon 12 Dec 2016 10:25:56 AM PST      Build Host: ls20-bc2-14.build.redhat.com
Group       : Applications/Editors          Source RPM: nano-1.3.12-1.1.src.rpm
Size        : 1340343                          License: GPL
Signature   : DSA/SHA1, Thu 18 Jan 2007 08:10:45 AM PST, Key ID 5326810137017186
Packager    : Red Hat, Inc. 
URL         : http://www.nano-editor.org
Summary     : A small text editor
Description :
GNU nano is a small and friendly text editor.

Where:

  • i – For Information

Query all Installed rpm Packages in Scrollable Manner ( Using more)

We can query all installed packages by using “rpm -qa” but this will list all installed packages at once and if the list is too long then we unable to check all the packages properly, to overcome this we can use more with help of a filter ( | ). more will show the output in a scrollable manner and one screen at a time and the screen will end with –More–. We can see the next screen by pressing the SPACE bar on the keyboard.

Example:

 # rpm -qa | more
tzdata-2010e-1.el5
gnome-audio-2.0.0-3.1.1
redhat-release-notes-5Server-31
libstdc++-4.1.2-48.el5
info-4.8-14.el5
freetype-2.2.1-21.el5_3
db4-4.3.29-10.el5
zlib-1.2.3-3
freetype-2.2.1-21.el5_3
libjpeg-6b-37
ncurses-5.5-24.20060715
--More--

Check dependencies of an rpm package before install

We can check the required dependencies of an rpm package before installing it using rpm command with -qpR, Here I am checking the dependencies of the tomcat5 package as shown below.

Example:

 # rpm -qpR tomcat5-5.5.23-0jpp.7.el5_3.2.x86_64.rpm 
warning: tomcat5-5.5.23-0jpp.7.el5_3.2.x86_64.rpm: Header V3 DSA signature: NOKEY, key ID 37017186
/bin/bash 
/bin/sh 
config(tomcat5) = 0:5.5.23-0jpp.7.el5_3.2
jakarta-commons-daemon >= 1.0.1
jakarta-commons-launcher >= 0:0.9
java-gcj-compat >= 1.0.31
java-gcj-compat >= 1.0.31
.
.
tomcat5-common-lib = 0:5.5.23-0jpp.7.el5_3.2
tomcat5-server-lib = 0:5.5.23-0jpp.7.el5_3.2
xerces-j2 >= 0:2.7.1
xml-commons-apis >= 1.3

Where:

  • R – To check dependencies of a Package

Check the Documents related to the rpm package

To check the documents related to any rpm package we can use the rpm command with -qdf, Refer to the example below.

Example:

 [root@localhost ~]# which fdisk 
/sbin/fdisk
[root@localhost ~]# rpm -qdf /sbin/fdisk 
/usr/share/doc/util-linux-2.13/AUTHORS
/usr/share/doc/util-linux-2.13/NEWS
/usr/share/doc/util-linux-2.13/README.cal
/usr/share/doc/util-linux-2.13/README.clear
/usr/share/doc/util-linux-2.13/README.col
/usr/share/doc/util-linux-2.13/README.fdisk
/usr/share/doc/util-linux-2.13/README.getty
/usr/share/doc/util-linux-2.13/README.html
.
.
/usr/share/man/man8/umount.8.gz
/usr/share/man/man8/vigr.8.gz
/usr/share/man/man8/vipw.8.gz

Where:

  • d – To check Documentation of an rpm Package

Check recently installed rpm packages

To check recently installed rpm packages use the rpm -qa with –last, follow the example below.

Example:

 
# rpm -qa --last

tomcat5-5.5.23-0jpp.7.el5_3.2                 Sat 24 Dec 2016 06:08:55 AM PST
dhcp-3.0.5-23.el5                             Sat 24 Dec 2016 05:45:07 AM PST
systemtap-1.1-3.el5                           Mon 12 Dec 2016 10:35:06 AM PST
dogtail-0.6.1-3.el5                           Mon 12 Dec 2016 10:35:06 AM PST
.
.
xorg-x11-drv-voodoo-1.1.0-3.1                 Mon 12 Dec 2016 10:34:15 AM PST
xorg-x11-drv-via-0.2.1-9                      Mon 12 Dec 2016 10:34:15 AM PST

Query dependencies of an Installed rpm Package:

We can find what dependencies the installed rpm package has by using the rpm command with -qR option, refer to the example below.

Example:

   # rpm -qR dhcp
   /bin/sh  
   /bin/sh  
   /bin/sh  
   /bin/sh  
   chkconfig  
   chkconfig  
   config(dhcp) = 12:3.0.5-23.el5
   coreutils  
   coreutils  
   libc.so.6()(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)  
   rpmlib(CompressedFileNames) <= 3.0.4-1
   rpmlib(PayloadFilesHavePrefix) <= 4.0-1
   rtld(GNU_HASH) 

List the Configuration files of an rpm Package

To list the configuration files of a Package use the rpm command with -qc option, Here I am checking the configuration file of Package Vsftpd as shown below.

Example:

   # rpm -qc vsftpd
   /etc/logrotate.d/vsftpd.log
   /etc/pam.d/vsftpd
   /etc/vsftpd/ftpusers
   /etc/vsftpd/user_list
   /etc/vsftpd/vsftpd.conf
   /etc/vsftpd/vsftpd_conf_migrate.sh

Where:

  • c – To check configuration files of a Package

List the Configuration files of a Command

To check the configuration file of a command using the below command, Refer the example below.

Example:

   # rpm -qcf /usr/bin/yum 
   /etc/logrotate.d/yum
   /etc/yum.conf

Check the Information contained by rpm

To check the information of an rpm package we can use the rpm command with -qip, Here I am checking the information of dhcp-3.0.5-23.el5.x86_64.rpm as shown below.

Information are contains by the rpm package is listed below :

  • Name of the Package
  • Version
  • Release Date
  • Size
  • Signature
  • Packager
  • Description

Example:

# rpm -qip dhcp-3.0.5-23.el5.x86_64.rpm
   warning: dhcp-3.0.5-23.el5.x86_64.rpm: Header V3 DSA signature: NOKEY, key ID 37017186
   Name        : dhcp                         Relocations: (not relocatable)
   Version     : 3.0.5                             Vendor: Red Hat, Inc.
   Release     : 23.el5                        Build Date: Tue 26 Jan 2010 08:28:40 AM PST
   Install Date: (not installed)               Build Host: x86-004.build.bos.redhat.com
   Group       : System Environment/Daemons    Source RPM: dhcp-3.0.5-23.el5.src.rpm
   Size        : 2317042                          License: distributable
   Signature   : DSA/SHA1, Tue 23 Feb 2010 11:53:20 PM PST, Key ID 5326810137017186
   Packager    : Red Hat, Inc. 
   URL         : http://isc.org/products/DHCP/
   Summary     : A DHCP (Dynamic Host Configuration Protocol) server and relay agent.
   Description :
   DHCP (Dynamic Host Configuration Protocol) is a protocol which allows
   individual devices on an IP network to get their own network
   configuration information (IP address, subnetmask, broadcast address,
   etc.) from a DHCP server. The overall purpose of DHCP is to make it
   easier to administer a large network.  The dhcp package includes the
   ISC DHCP service and relay agent.

   To use DHCP on your network, install a DHCP service (or relay agent),
   and on clients run a DHCP client daemon.  The dhcp package provides
   the ISC DHCP service and relay agent.

Query the Configuration files of an rpm Package

If you want to check the configuration files contained by the rpm package before installation uses the rpm command with -qlp option, Refer to the example below.

   # rpm -qlp dhcp-4.1.1-51.P1.el6.centos.x86_64.rpm 
   /etc/dhcp
   /etc/dhcp/dhcpd.conf
   /etc/dhcp/dhcpd6.conf
   /etc/openldap/schema/dhcp.schema
   .
   .
   /var/lib/dhcpd
   /var/lib/dhcpd/dhcpd.leases
   /var/lib/dhcpd/dhcpd6.leases

2. Install :

Install a Package using rpm

To install a package using the rpm command with the option I, Here I am installing the DHCP package as shown below.

Example:

   # rpm -ivh dhcp-3.0.5-23.el5.x86_64.rpm 
   warning: dhcp-3.0.5-23.el5.x86_64.rpm: Header V3 DSA signature: NOKEY, key ID 37017186
   Preparing...                ########################################### [100%]
      1:dhcp                   ########################################### [100%]

Where:

  • i – To Install a Package
  • v – To print verbose information
  • h – For hash output

Install a Package without checking for Dependencies

Each and every package needs some dependencies to install. As we can see below when I am trying to install the tomcat5 package it’s asking for so many dependencies.

Example:

# rpm -ivh tomcat5-5.5.23-0jpp.7.el5_3.2.x86_64.rpm 
   warning: tomcat5-5.5.23-0jpp.7.el5_3.2.x86_64.rpm: Header V3 DSA signature: NOKEY, key ID 37017186
   error: Failed dependencies:
           jakarta-commons-daemon >= 1.0.1 is needed by tomcat5-5.5.23-0jpp.7.el5_3.2.x86_64
           jakarta-commons-launcher >= 0:0.9 is needed by tomcat5-5.5.23-0jpp.7.el5_3.2.x86_64
           .           
           .
           xerces-j2 >= 0:2.7.1 is needed by tomcat5-5.5.23-0jpp.7.el5_3.2.x86_64
           xml-commons-apis >= 1.3 is needed by tomcat5-5.5.23-0jpp.7.el5_3.2.x86_64

But if you want to install the package without checking for dependencies then you can use the rpm command with option –nodepc, Here I am installing tomcat5 without checking for dependencies as shown below.

 # rpm -ivh --nodepc tomcat5-5.5.23-0jpp.7.el5_3.2.x86_64.rpm 
   --nodepc: unknown option
   [root@localhost ~]# rpm -ivh --nodeps tomcat5-5.5.23-0jpp.7.el5_3.2.x86_64.rpm 
   warning: tomcat5-5.5.23-0jpp.7.el5_3.2.x86_64.rpm: Header V3 DSA signature: NOKEY, key ID 37017186
   Preparing...                ########################################### [100%]
      1:tomcat5                ########################################### [100%]

3. Upgrade :

Upgrade an rpm Package

To upgrade a package from lower version to upper version we can use the rpm command with -U option, Here I am upgrading the DHCP package from version dhcp-3.0.5-23 to dhcp-4.1.1.51

# rpm -qa | grep dhcp
   dhcp-3.0.5-23.el5.i386

   [root@localhost ~]# rpm -Uvh dhcp-4.1.1-51.P1.el6.centos.x86_64.rpm 
   Preparing...                ########################################### [100%]
      1:dhcp                   ########################################### [100%]

   [root@localhost ~]# rpm -qa | grep dhcp
   dhcp-4.1.1-51.P1.el6.centos.x86_64

Where:

  • U – To Upgrade a Package

4. Uninstall :

Uninstall an rpm Package

To Uninstall a Package we can use rpm package with option -e, Here I am uninstalling DHCP package as shown below.

Example:

 # rpm -ev dhcp

Where:

  • e – To erase/uninstall a package

Uninstall an rpm Package without checking for Dependencies

To Uninstall a Package Without checking for dependencies we can use the rpm command with –nodeps option, Here I am removing the HTTPd package using –nodeps as shown below.

Example:

  # rpm -qa | grep httpd
   httpd-2.2.3-43.el5

   # rpm -ev --nodeps httpd-2.2.3-43.el5
   warning: /etc/httpd/conf/httpd.conf saved as /etc/httpd/conf/httpd.conf.rpmsave

5. Verification :

Verify all packages using rpm

To verify all packages install on the system we can use the rpm command with -Va as shown below.

Example:

# rpm -Va

Where:

  • V – To verify a Package

Verify a particular package using rpm

To verify a particular package use the rpm command with the -Vp option, Here I am verifying the DHCP package as shown below.

Example:

# rpm -Vp dhcp-3.0.5-23.el5.x86_64.rpm
warning: dhcp-3.0.5-23.el5.x86_64.rpm: Header V3 DSA signature: NOKEY, key ID 37017186

some Useful rpm Command Options :

  • i – Install a Package
  • v – For Verbose Output
  • h – For Hash progress output
  • q – To query a package
  • V – to verify a Package
  • U – Upgrade a Package from lower version to upper version
  • R – To check Dependencies of a Package or a File
  • a – to check all packages
  • f – to mention a file
  • l – to list files or directories
  • i – for Information of a package ( Note: Can be used with -q )
  • d – query the documentation of a package
  • c – find configuration files of the package or a command

We tried to include as many as commands we can If any commands got missed the Please update us in the Comment box below.

That’s all, In this article, we have explained the Useful RPM Command With Examples In Linux. I hope you enjoy this article. If you like this article, then just share it. If you have any questions about this article, please comment.

Share this:
WhatsApp Channel Join Now
Telegram Channel Join Now
Instagram Channel Join Now

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.