Frequently Used RPM Commands On Linux Server

Frequently Used RPM Commands On Linux Server

Frequently Used RPM Commands On Linux Server : In this session we will focus on some useful RPM command with Examles. RPM Stands for Redhat Package Manager which is responsible for Installing, Verifying, Upgrading, Querying and Uninstalling packages. These are the five major tasks we can perform with RPM which are explained below :-

  • Query: Query the system means check the local database and give the report about total installed Packages, which configuration file is belongs to which package For Example let’s take a configuration file “/etc/passwd“, now we can find out the “passwd” is belongs to which .rpm package.
  • Install: This will allow you to install a fresh package with extension .rpm.
  • Erase or Uninstallation: This will allow you to erase of uninstall a already installed packages.
  • Upgrade: This will allow you to upgrade installed packages from lower version to upper released version without loosing the customized settings.
  • Verify:  Verify the Package before Installation.

A RPM package would contains information like file name, package version, package release date, documentation of the package description..etc…

The database location of the RPM is /var/lib/rpm where it’s store’s information about installed packages such as file attributes and package prerequisites…etc…

RPM is both a command and a back-end support for other program such as yum.

The Structure of the RPM file would look like this :-

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

Let’s compare the above rpm pattern with 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 Useful and Important commands of RPM, I have categorized rpm commands as per it’s use like Query, Installation, Uninstallation, Up-gradation and Verification.

1. Query :

Query all Installed rpm Packages

To query all installed packages in 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 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 a 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 findout the file ( e.g. configurations file ) belongs to which rpm package we can use 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

To list files and directories with it’s location of an installed rpm package

To list the files and directories with it’s location installed by the package we can use the rpm command with option -ql as 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 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 Scrolleable 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 from this we can use more with help of 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 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 a rpm package before install

We can check the required dependencies of a rpm package before installing it using rpm command with -qpR, Here i am checking dependencies of 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 rpm package

To check the documents related to any rpm package we can use rpm command with -qdf, Refer the exmaple 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 a 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 a Installed rpm Package

We can find what dependencies the installed rpm package has by using rpm command with -qR option, refer 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 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 use 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 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 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 a rpm Package

If you want to check the configuration files contained by rpm package before installation use the rpm command with -qlp option, Refer 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

Also Read :

2. Install :

Install a Package using rpm

To install a package use the rpm command with option i, Here i am installing 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 install 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 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 a rpm Package

To upgrade a package from lower version to upper version we can use 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 a 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 a rpm Package without checking for Dependencies

To Uninstall a Package Without checking for dependencies we can use rpm command with –nodeps option, Here I am removing 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 system we can use 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 rpm command with -Vp option, Here i am verifying 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 package or a command

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

Was this Tutorial helpful? Help others share on Facebook, Twitter, and Google Plus!

 
Enjoyed this video?
Frequently Used RPM Commands On Linux Server
"No Thanks. Please Close This Box!"