1. Overview

System administrators use the rpm (Red Hat Package Manager) command-line utility for Unix/Linux package management. Specifically, the rpm command streamlines the process of installing, querying, verifying, and managing software packages.

In this tutorial, we’ll delve into the various facets of the rpm command, exploring its usage, common options, and real-world examples.

2. Understanding the rpm Command

First, let’s understand the basics of rpm.

The rpm command comes installed as a native utility for Linux distributions based on Red Hat, such as Red Hat Enterprise Linux (RHEL), CentOS, and Fedora:

$ rpm --version
RPM version 4.18.2

Consequently, as shown above, the output indicates that this current Linux system has the rpm utility installed, and the version is 4.18.2.

Next, the basic syntax of rpm comprises two parameters:

$ sudo rpm [options] [package_name]

Now, let’s break down the rpm command syntax:

  • sudo: allows running other commands with elevated privileges as root
  • rpm: invokes the Red Hat Package Manager
  • [options]: the various flags and options that modify the behavior of the rpm command
  • [package_name]: the name of the package to operate on, which could be an installed package or a package file with the .rpm extension

Now that we’ve covered the syntax, let’s examine the basic usage of the rpm command.

 3. Basic rpm Command Usage

To begin with, let’s explore the most commonly used options of the rpm command:

Options Description
-i, –install Installs a package
-e, –erase Removes a package
-h, –hash Prints a progress bar (hash marks) as the package installs
-l, –list Lists files in a package
-q, –query Queries a package
-s, –state Displays the state of the listed files
-U, –upgrade Upgrades a package
-v, –verbose Provides more detailed output
-V, –verify Verifies the integrity of installed packages
-a, –all Queries all installed packages

Subsequently, let’s apply these commands to rpm packages in practice.

3.1. Installing an rpm Package

To commence, we take a close look at the -ivh options’ combined usage.

So, the -ivh option instructs the rpm command to install an rpm software package, print detailed output, and display a progress bar. For example, let’s install the MySQL community version via its rpm package:

$ sudo rpm -ivh mysql84-community-release-el9-1.noarch.rpm
...
Verifying...                          ################################# [100%]
Preparing...                          ################################# [100%]
Updating / installing...
   1:mysql84-community-release-el9-1  ################################# [100%]

From the above result, we can see that the verification, preparation, and installation were completely successful.

3.2. Updating Packages

Next, the -U option prompts the rpm command to update an already-installed package or install it otherwise:

$ sudo rpm -Uvh mysql84-community-release-el9-1.noarch.rpm
... 
warning: mysql84-community-release-el9-1.noarch.rpm: Header V4 RSA/SHA256 Signature, key ID a8d3785c: NOKEY
Verifying...                          ################################# [100%]
Preparing...                          ################################# [100%]
	package mysql84-community-release-el9-1.noarch is already installed

In this case, the package is already installed and up-to-date. However, the command still verified and prepared the package in case it needed to be updated or installed.

3.3. Uninstalling Packages

The -e option prompts the rpm command to erase (uninstall) a specified package. Note that this works on already-installed packages.

Now, let’s uninstall the mysql84-community-release-el9-1.noarch we installed initially:

$ sudo rpm -evh mysql84-community-release-el9-1.noarch
Preparing...                          ################################# [100%]
Cleaning up / removing...
   1:mysql84-community-release-el9-1  ################################# [100%]

The output above shows that the package was cleanly removed. Moreover, let’s confirm if the package has been erased completely:

$ sudo rpm -qa | grep mysql

Consequently, the command didn’t display any packages because the package had already been uninstalled and erased. More so, the -qa option queries all installed packages, and the grep command filters the output for packages containing mysql in the package name.

3.4. Package Verification

The -V (or –verify) option checks the integrity and authenticity of installed packages against the RPM database. In addition, for real-time output, let’s include the -v option, too, for additional details:

$ sudo rpm -Vv mysql84-community-release-el9-1.noarch 
.........    /etc/pki/rpm-gpg/RPM-GPG-KEY-mysql-2022
...
.........  c /etc/yum.repos.d/mysql-community-source.repo
.........  c /etc/yum.repos.d/mysql-community.repo

In general, the detailed verification checks ensure that the integrity and authenticity of these files are intact.

3.5. Status of Installed Packages

The -s option instructs the rpm command to display the state of each file in the package. Consequently, it allows an understanding of the current status of the files:

$ sudo rpm -qs mysql84-community-release-el9-1.noarch
normal        /etc/pki/rpm-gpg/RPM-GPG-KEY-mysql-2022
...
normal        /etc/yum.repos.d/mysql-community.repo

In contrast, the difference between this and the previous output is the inclusion of status. Moreover, we can see that all the statuses are normal, indicating that these files are in their expected state.

4. Advanced Usage

Let’s touch on a few advanced usages of the rpm command and options.

4.1. Information About a Package

Understanding a package before installation is crucial. Let’s examine how to use the rpm command with the -qip option to gather information about a package:

$ sudo rpm -qip mysql84-community-release-el9-1.noarch.rpm 
warning: mysql84-community-release-el9-1.noarch.rpm: Header V4 RSA/SHA256 Signature, key ID a8d3785c: NOKEY
Name        : mysql84-community-release
Version     : el9
Release     : 1
Architecture: noarch
Install Date: (not installed)
Group       : System Environment/Base
...
URL         : http://dev.mysql.com
Summary     : MySQL repository configuration for yum
Description :
Package for installation of setup/configuration files required for
installation of MySQL packages by yum.

The result above shows detailed information about mysql84-community-release-el9-1.noarch.rpm, from the name to the description of the package.

4.2. Installation Test Run

Simulating package installation helps determine whether the installation of a package will be successful. The -ivh –test option tells rpm to carry out a test run installation on a specified package without installing it:

$ rpm -ivh --test mysql84-community-release-el9-1.noarch.rpm
warning: mysql84-community-release-el9-1.noarch.rpm: Header V4 RSA/SHA256 Signature, key ID a8d3785c: NOKEY
Verifying...                          ################################# [100%]
Preparing...                          ################################# [100%]

As shown above, the output confirms the installation is successful and safe to proceed.

5. Conclusion

In this article, we delved into the use of rpm for package management. From basic installation and removal to advanced verification and information gathering, mastering rpm commands enhances system administration efficiency.

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments