12 RPM (Red Hat Package Manager) Command Examples

Overview :

RPM is an open source Package Manager on Linux Like Operating system(RHEL , CentOS & Fedora).RPM command is used to build, install, query, verify, update and erase individual software packages. RPM utility only works with packages that built on .rpm format. An RPM file contains not only the software files but also in-depth information about the software, such as what it’s called, when it was released, what changes have been made, and what other packages it depends on to work.

The Local RPM database is maintained in /var/lib/rpm. The database stores information about installed packages such as file attributes and package prerequisites.

RPM file Formart :name-version-release.architecture.rpm

Where version refers to the open source  version of the project , while the release refers to the Red Hat internals patches to the open source code. Architecture shows the information about architecture (32 bit or 64 bit)
rpm is a backend for other programs such as yum or system-config-packages. These tools provide significant advantages such as automatic dependency resolution.

Synatx :

# rpm <options> <rpmfile>

Primary RPM Options :

  • Install : rpm -i , –install
  • Upgrade : rpm -U , –upgrade
  • Freshen : rpm -F , –freshen
  • Erase : rpm -e , –erase
  • Query: rpm -q , –query
  • output options: -v , -h

Example:1 Installing the RPM Package

#  rpm -ivh  vim-enhanced-7.2.411-1.8.el6.x86_64.rpm
Preparing...                ########################################### [100%]
1:vim-enhanced           ########################################### [100%]

Where :

-i : install a package
-v : verbose output
-h: print hash marks as the package archive is unpacked.

Example:2 Installing  rpm packages without dependencies

# rpm -ivh  --nodeps vim-enhanced-7.2.411-1.8.el6.x86_64.rpm

 

Example:3 Remove / erase rpm package

#  rpm -ev vim-enhanced

 

Example:4 Upgrade RPM package using -U and -F options

rpm can be used to upgrade already installed software with -U (–upgrade) command line option,When upgrading , the original package(with the exception of configuration files ) on the system will be removed and new package installed. Configuration files from the original installation are saved with a “.rpmsave” extension.
Freshening is almost identical to upgrading , except when the package specified on the command line is not already installed on the system.When upgrading with -U , the package will be installed whether or not it is already installed. But in case of freshening , the package will be ignored if not already installed.

Syntax # rpm -Uvh  <rpm-file>

# rpm -Uvh mozilla-mail-1.7.6-12.i586.rpm

Syntax # rpm -Fvh  <rpm-file>

# rpm -Fvh mozilla-mail-1.7.6-12.i586.rpm

 

Example:5 Display all installed packages

#  rpm -qa 
# rpm -qa |  less

Example:6  Display list of configuration file(s) for a package

Syntax # rpm -qc <package-name>

rpm-qc

Example:7 Find out what package a file belongs to  OR find what package owns the file

# rpm -qf </path/to/file>

rpm-qf

Example:8 Display the information of installed package : version & Description

# rpm -qi <package name>

rpm-qi

Example:9 Display the list of all recently installed RPMs

#  rpm -qa --last 
#  rpm -qa --last | less

 

Example:10 Check the dependencies of a rpm file before installation

# rpm -qpR  <.rpm-file>

where :

-q : Query a package
-p : List capabilities this package provides.
-R: List capabilities on which this package depends.

rpm-qrp

Example:11 Verify a RPM Package

Verifying a package means compares information of installed files of the package against the rpm database. The -Vp (verify package) is used to verify a package.

#  rpm -Vp vim-enhanced-7.2.411-1.8.el6.x86_64.rpm

To Verify all rpm packages

# rpm -Va

 

Example:12 Import  RPM GPG keys

To verify RHEL/CentOS rpm packages, first we must import the GPG key, to import the key use the below command. It will import CentOS 6 GPG key.

#  rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6


Leave a Reply

Your email address will not be published. Required fields are marked *