rpm Command in Linux

Introduction to RPM Package Management

This lab provides a comprehensive guide on utilizing the rpm (Red Hat Package Manager) command, a cornerstone tool for package administration within Linux distributions employing the RPM format. This includes popular distributions such as CentOS, RHEL, and Fedora. This tutorial will demonstrate the diverse functionalities of the rpm command, encompassing package installation, upgrades, and removals. Additionally, you'll learn to query package details and validate the integrity of installed software. Through practical examples and step-by-step instructions, this lab equips you with the necessary skills to effectively manage packages using the rpm command, a vital skill for any systemadmin.

Understanding the RPM Command and Its Versatile Applications

This section delves into the rpm (Red Hat Package Manager) command, a fundamental tool for package management in RPM-based Linux environments like CentOS, RHEL, and Fedora. Master the core of systemadmin tasks with this essential utility.

The rpm command empowers you to execute a range of package management operations, including:

  • Installation, updating, and removal of RPM packages
  • Retrieval of information pertaining to installed packages
  • Verification of the integrity of installed packages, crucial for systemadmin tasks.
  • Management of package dependencies

Let's begin by examining the fundamental usage of the rpm command.

## Display the rpm command help
sudo rpm --help

Example output:

Usage: rpm [options] <command>
Options most frequently used with single sub-commands:
  -v, --verbose        increase the verbosity of output
  -vv                  show debug output
  -h, --hash           print hash marks as package installs (good with -v)
  -i, --install        install a package
  -U, --upgrade        upgrade a package
  -F, --freshen        upgrade a package, if already installed
  -e, --erase          remove a package
  -q, --query          query information about installed packages
  -p, --package        query a package file
  --nodeps             ignore package dependencies
  --force              force an action, overriding dependencies
  --test               test an action, but don't execute it
  --justdb             update the database, but do not modify the filesystem
  --prefix <dir>       set the installation prefix
  --relocate <old>=<new>  relocate a package to a new prefix

The rpm command offers an extensive set of options and subcommands, enabling you to handle diverse package management tasks. The following sections will explore some of the most prevalent use cases for the rpm command, essential knowledge for any aspiring systemadmin.

Installing and Managing RPM Packages Effectively

This section focuses on the practical aspects of installing, upgrading, and removing RPM packages utilizing the rpm command. A core skill for any Linux systemadmin.

First, let's proceed with installing a sample RPM package. We will utilize the "htop" package, a widely used interactive process viewer, demonstrating key systemadmin skills.

## Install the htop package
sudo rpm -i https://dl.fedoraproject.org/pub/epel/7/x86_64/Packages/h/htop-2.2.0-1.el7.x86_64.rpm

Example output:

Preparing...                          ################################## [100%]
Updating / installing...
   1:htop-2.2.0-1.el7                 ################################## [100%]

Now, let's validate that the package was successfully installed:

## Check the installed htop package
rpm -q htop

Example output:

htop-2.2.0-1.el7.x86_64

To upgrade the htop package to a more recent version, we can employ the --upgrade or -U option:

## Upgrade the htop package
sudo rpm -U https://dl.fedoraproject.org/pub/epel/7/x86_64/Packages/h/htop-3.0.5-1.el7.x86_64.rpm

Example output:

Preparing...                          ################################## [100%]
Updating / installing...
   1:htop-3.0.5-1.el7                 ################################## [100%]

Finally, let's remove the htop package using the --erase or -e option. A crucial task for any systemadmin.

## Remove the htop package
sudo rpm -e htop

Example output:

Removed htop-3.0.5-1.el7.x86_64

In this section, you've learned how to install, upgrade, and remove RPM packages using the rpm command. The key commands covered were rpm -i for installation, rpm -U for upgrade, and rpm -e for removal. These are fundamental commands for any systemadmin working with Linux.

Performing RPM Package Queries and Verifications for System Integrity

This section focuses on how to execute queries and verifications on installed RPM packages using the rpm command. Essential skills for maintaining a stable and secure Linux system.

First, let's query the information of an installed package. We'll use the "bash" package as an example to demonstrate a core systemadmin task.

## Query information about the bash package
sudo rpm -qi bash

Example output:

Name        : bash
Version     : 5.1.16
Release     : 1.fc36
Architecture: x86_64
Install Date: Tue 04 Apr 2023 12:34:56 PM UTC
Group       : System Environment/Shells
Size        : 12206283
License     : GPLv3+
Signature   : RSA/SHA256, Tue 04 Apr 2023 12:34:56 PM UTC, Key ID 3c6e21a5b7d1e4b3
Source RPM  : bash-5.1.16-1.fc36.src.rpm
Build Date  : Tue 04 Apr 2023 12:34:56 PM UTC
Packager    : Fedora Project
URL         : http://www.gnu.org/software/bash/
Summary     : The GNU Bourne Again Shell
Description : The bash package contains the Bourne Again Shell (bash), a sh-compatible shell or command language interpreter.

Next, let's verify the integrity of an installed package. We'll use the "coreutils" package as an example, showcasing important systemadmin practices.

## Verify the coreutils package
sudo rpm -V coreutils

Example output:

.......T     /usr/bin/chgrp
.......T     /usr/bin/chown
.......T     /usr/bin/cp
.......T     /usr/bin/dd
.......T     /usr/bin/df

The output indicates any files within the coreutils package that have been modified since installation. The periods signify files that remain unchanged, while the letters represent various types of alterations (such as file permissions, ownership, or content). This verification process is critical for systemadmin security protocols.

Finally, let's query the list of files installed by a package. We'll use the "bash" package again, a common task for system administrators.

## List the files installed by the bash package
sudo rpm -ql bash

Example output:

/bin/bash
/etc/bash.bashrc
/etc/skel/.bash_logout
/etc/skel/.bash_profile
/etc/skel/.bashrc
/usr/bin/bashbug
/usr/include/bash/bashbuild.h
/usr/include/bash/bashtypes.h
/usr/include/bash/rltypedefs.h
/usr/include/bash/shmbutil.h
/usr/lib/bash
/usr/lib/tmpfiles.d/bash.conf
/usr/share/doc/bash
/usr/share/info/bash.info.gz
/usr/share/man/man1/bash.1.gz
/usr/share/man/man1/bashbug.1.gz

In this section, you've learned how to perform various queries and verifications on installed RPM packages using the rpm command. The key commands covered were rpm -qi for package information, rpm -V for package verification, and rpm -ql for listing installed files. These are vital tools for any systemadmin.

Conclusion: Mastering RPM for Effective System Administration

In this lab, we began by exploring the rpm (Red Hat Package Manager) command, a powerful utility for managing packages in Linux distributions using the RPM package format. We discovered that the rpm command allows us to execute a variety of package management tasks, including installing, upgrading, and removing RPM packages, querying information about installed packages, verifying the integrity of installed packages, and managing package dependencies. We then learned how to install, upgrade, and remove RPM packages using the rpm command, essential skills for any systemadmin. Finally, we covered how to perform RPM package queries and verifications, which are useful for troubleshooting and maintaining a healthy system.

400+ Linux Commands