RPM Command to Manage Packages on RHEL/CentOS/Fedora Systems

Nowadays most Linux administrators only use front-ent package managers such as YUM Package Manager or DNF Package Manager on Fedora and RHEL-based systems.

This is a very simple and powerful package management tool that automatically solves dependencies for packages.

But sometimes you may need to use RPM Package Manager because the required package is not available in your repository or the application developer may only provide the rpm package.

What is RPM Package Manager

RPM refers to RPM Package Manager (formerly known as Red Hat Package Manager) is a powerful, command-line package management tool developed for the Red Hat operating system.

It is now used as a core component in many Linux distributions such as Centos, Fedora, Oracle Linux, openSUSE and Mageia.

RPM Package Manager allows you to install, upgrade, delete, query and verify packages on RPM-based Linux systems.

RPM files comes with the .rpm extension. The RPM package consists of an archive file, that contains libraries and dependencies for a specific package, that do not conflict with other packages installed on your system.

There are many front-end tools available on Linux to install the RPM package that make the installation process more efficiently compared to the RPM tool, especially for handling dependencies.

If you want to know more about the front-end package manager of Linux distributions, go to the link below.

If you would like GUI package manager for Linux, go to the link below.

RPM File Naming Convention

The RPM package file name provides some important information about the package such as package name, package version, release and the hardware architecture.

The format of rpm package name is as follows:

httpd-2.4.6-92.el7.x86_64.rpm

+---------+---------------------------------+
|  Data   |         Description             |
+---------+---------------------------------+
| httpd   | Name of the actual package      |
| 2.4.6   | Version of package release      |
| 92      | Subversion of package release   |
| el7     | Red Hat Version                 |
| x86_64  | Hardware architecture           |
| rpm     | File extension                  |
+---------+---------------------------------+

1) How to Download an rpm File

You can easily download an rpm package using the yum command or dnf command from the distribution official repository.

If it is not available in the official repository of distribution, you should download it from third-party RPM websites

Use the yumdownloader tool to download RPM packages on RHEL/CentOS 6 and 7 systems.

# yumdownloader nano

Loaded plugins: product-id, subscription-manager, versionlock
rhel-7-server-rpms                                      | 2.0 kB  00:00:00
nano-2.3.1-10.el7.x86_64.rpm                            | 440 kB  00:00:00

For RHEL/CentOS 8 and Fedora systems, use the dnf command.

# dnf download nano

Use the ls command to view the downloaded rpm file.

# ls -lh nano*
-rw-r--r--. 1 root root 440K Nov  8  2018 nano-2.3.1-10.el7.x86_64.rpm

Known third-party websites are listed below:

2) How to Check an RPM Signature Against a Package

Always check the PGP signature before installing an RPM package on your Linux machine and make sure its integrity and origin are “OK”. Use the following option with the rpm command to verify them.

# rpm --checksig nano-2.3.1-10.el7.x86_64.rpm
nano-2.3.1-10.el7.x86_64.rpm: rsa sha1 (md5) pgp md5 OK

3) How to Install an RPM Package

To install a rpm package on a Linux system, use the -i option with the rpm command. To demonstrate this, we are going to install the “nano” package on the system.

# rpm -ivh nano-2.3.1-10.el7.x86_64.rpm
Preparing...                ########################################### [100%]
   1:nano                   ########################################### [100%]

Details

  • -i: To install a package
  • -v: Verbose
  • -h: This print hash marks as the package archive is unpacked

4) How to Query a Specific Installed RPM Package

The “nano” package has already installed on the system in the above step so, we are now going to query that package. To do so, use the -q option with the rpm command.

# rpm -q nano
nano-2.0.9-7.el6.x86_64

If the given package is not installed on your system, you will get the following error.

# rpm -q nano
package nano is not installed

Details

  • -q : query operation

5) How to Query All Installed RPM Packages

If you want to query all the rpm packages installed on your system, use the -qa option with the rpm command.

# rpm -qa

avahi-libs-0.6.25-15.el6.x86_64
setuptool-1.19.9-4.el6.x86_64
basesystem-10.0-4.el6.noarch
.
.

6) How to Check the Detailed Information of the Installed RPM Package

Use the -qi option with the rpm command to verify detailed information about the rpm package installed on your system.

# rpm -qi nano

Name        : nano                         Relocations: (not relocatable)
Version     : 2.0.9                             Vendor: CentOS
Release     : 7.el6                         Build Date: Fri 12 Nov 2010 08:18:36 AM CET
Install Date: Wed 07 Oct 2015 02:20:03 PM CEST      Build Host: c5b2.bsys.dev.centos.org
Group       : Applications/Editors          Source RPM: nano-2.0.9-7.el6.src.rpm
Size        : 1588347                          License: GPLv3+
Signature   : RSA/8, Sun 03 Jul 2011 06:46:50 AM CEST, Key ID 0946fca2c105b9de
Packager    : CentOS BuildSystem 
URL         : http://www.nano-editor.org
Summary     : A small text editor
Description :
GNU nano is a small and friendly text editor.

7) How to Get Detailed Information About an RPM Package Before Installing it

If you would like to know more about an rpm package before installing it on your system, use the -qip option with the rpm command.

# rpm -qip nano-2.0.9-7.el6.x86_64.rpm

Name        : nano                         Relocations: (not relocatable)
Version     : 2.0.9                             Vendor: CentOS
Release     : 7.el6                         Build Date: Fri 12 Nov 2010 08:18:36 AM CET
Install Date: (not installed)               Build Host: c5b2.bsys.dev.centos.org
Group       : Applications/Editors          Source RPM: nano-2.0.9-7.el6.src.rpm
Size        : 1588347                          License: GPLv3+
Signature   : RSA/8, Sun 03 Jul 2011 06:46:50 AM CEST, Key ID 0946fca2c105b9de
Packager    : CentOS BuildSystem 
URL         : http://www.nano-editor.org
Summary     : A small text editor
Description :
GNU nano is a small and friendly text editor.

8) How to List Files From an RPM File

If you want to know the list of files with the given rpm file, use the -qlp option with the rpm command.

# rpm -qlp nano-2.0.9-7.el6.x86_64.rpm

/bin/nano
/bin/rnano
/etc/nanorc
/usr/bin/nano
/usr/bin/rnano
/usr/share/doc/nano-2.0.9
/usr/share/doc/nano-2.0.9/AUTHORS
/usr/share/doc/nano-2.0.9/BUGS
/usr/share/doc/nano-2.0.9/COPYING
/usr/share/doc/nano-2.0.9/ChangeLog

9) How to List Dependency Packages From an RPM File

If you want to know the list of dependent packages compiled with the given rpm file, use the -qRp option with the rpm command.

# rpm -qRp nano-2.0.9-7.el6.x86_64.rpm

/bin/sh
/bin/sh
/sbin/install-info
/sbin/install-info
config(nano) = 2.0.9-7.el6
libc.so.6()(64bit)
libc.so.6(GLIBC_2.11)(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)
libncursesw.so.5()(64bit)
libtinfo.so.5()(64bit)
rpmlib(CompressedFileNames) <= 3.0.4-1
rpmlib(FileDigests) <= 4.6.0-1
rpmlib(PayloadFilesHavePrefix) <= 4.0-1
rtld(GNU_HASH)
rpmlib(PayloadIsXz) <= 5.2-1

10) How to Verify all RPM Packages Installed on Your System

Verifying a package compares information about the installed files in the package with information about the files taken from the package metadata stored in the rpm database. This can be achieved by using the -Va option with the rpm command.

# rpm -Va

S.5....T.  c /etc/sysconfig/varnish
......G..    /usr/libexec/utempter/utempter
S.5....T.  c /etc/yum.repos.d/epel.repo
S.5....T.  c /etc/squid/squid.conf
S.5....T.  c /etc/issue
S.5....T.  c /etc/yum.repos.d/CentOS-Base.repo
.
.

11) How to Find an RPM Package That Provides a Specific File in Linux

If you want to find an rpm package that provides a specific binary file on Linux, use the -qf option with the rpm command.

# rpm -qf /usr/bin/nano

nano-2.0.9-7.el6.x86_64

12) How to List Files From the Installed RPM Package

If you want to know the list of installed files for the specific rpm package, use the -ql option with the rpm command.

# rpm -ql nano

/bin/nano
/bin/rnano
/etc/nanorc
/usr/bin/nano
/usr/bin/rnano
/usr/share/doc/nano-2.0.9
/usr/share/doc/nano-2.0.9/AUTHORS
/usr/share/doc/nano-2.0.9/BUGS
/usr/share/doc/nano-2.0.9/COPYING
/usr/share/doc/nano-2.0.9/ChangeLog

13) How to Check Recently Installed RPM Packages on Linux

Linux is a multi-user operating system, so other users may have installed some packages. If you want to find recently installed packages on your system, use the -qa --last option with the rpm command.

# rpm -qa --last

nano-2.0.9-7.el6.x86_64                       Wed 07 Oct 2015 02:20:03 PM CEST
varnish-libs-4.1.0-1.el6.x86_64               Fri 02 Oct 2015 03:55:42 PM CEST
varnish-4.1.0-1.el6.x86_64                    Fri 02 Oct 2015 03:55:42 PM CEST
gpg-pubkey-c4deffeb-4c872f3a                  Fri 02 Oct 2015 03:55:33 PM CEST
varnish-release-4.1-1.el6.noarch              Fri 02 Oct 2015 03:53:27 PM CEST
pcre-devel-7.8-7.el6.x86_64                   Fri 02 Oct 2015 03:44:18 PM CEST
libtool-2.2.6-15.5.el6.x86_64                 Fri 02 Oct 2015 03:44:18 PM CEST

14) How to Query Only the Documents of the Installed RPM Package

You can easily get help from the Linux Man page for any commands, but do you know where the documentation is coming from?

If not, then all of these come from "/usr/share/doc/Package_Name-Version_Number/docs*".

If you want to know the list of documents associated with the installed rpm package, use the -qdf option with the rpm command and enter the binary file path.

# rpm -qdf /usr/bin/nano

/usr/share/doc/nano-2.0.9/AUTHORS
/usr/share/doc/nano-2.0.9/ChangeLog
/usr/share/doc/nano-2.0.9/INSTALL
/usr/share/doc/nano-2.0.9/NEWS
/usr/share/doc/nano-2.0.9/README
/usr/share/doc/nano-2.0.9/THANKS
/usr/share/doc/nano-2.0.9/faq.html
/usr/share/info/nano.info.gz
/usr/share/man/man1/nano.1.gz
/usr/share/man/man1/rnano.1.gz
/usr/share/man/man5/nanorc.5.gz

15) How to Upgrade the Installed rpm Package

You can easily upgrade an already installed rpm package to the latest version by using the -Uvh option with the rpm command.

Make a note: When you upgrade the installed RPM package, it will remove the old one and install the new one.

# rpm -Uvh nano-2.0.9-7.el6.x86_64.rpm

Preparing...                ########################################### [100%]
   1:nano                   ########################################### [100%]

16) How to Remove the Installed rpm Package

If you want to remove the rpm package installed on your system, use the -ev options with the rpm command.

# rpm -ev nano

17) How To Rebuild a Corrupted RPM Database

You may occasionally receive an error message when trying to update the system by using the yum update command. The error message will be "rpm database got corrupted". If so, you can fix it using the steps below.

[Navigate to RPM database location]
# cd /var/lib/rpm

[Remove an existing RPM database]
# rm __db*

[Finally, rebuild the database]
# rpm --rebuilddb

18) How to Check if a Given Vulnerability is Fixed in a Specific Package in Linux

This can be achieved by using the --changelog option with the rpm command and entering the corresponding CVE.

# rpm -q --changelog python-2.6.6 | grep -i "CVE-2019-9636"

19) How to Import an RPM GPG key

By default, GPG keys are automatically imported when a new repository is added to the Linux system as part of the prerequisite. You can use the following rpm command to manually import the RPM GPG key.

This is used to check the integrity of the package when downloading from the repository.

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

20) How to List all Imported RPM GPG keys in Linux

Use the following rpm command to list all RPM GPG keys imported to your system.

# rpm -qa gpg-pubkey*

21) Visit the RPM Man Page

We have added all possible options in this article but if you are looking for any other option, which is not listed in this article visit man page.

# rpm -help
or
# man rpm

That’s all about the RPM command now, we’ll be bringing you a new topic soon, please stay tune with us..!

Magesh Maruthamuthu

Love to play with all Linux distribution

You may also like...