Linux rpm Command with Practical Examples

LinuxLinuxBeginner
Practice Now

Introduction

In this lab, you will learn how to effectively use the rpm (Red Hat Package Manager) command, a powerful tool for managing packages in Linux distributions that use the RPM package format, such as CentOS, RHEL, and Fedora. You will explore the various use cases of the rpm command, including installing, upgrading, and removing RPM packages, querying information about installed packages, and verifying the integrity of installed packages. The lab will provide practical examples and step-by-step guidance to help you become proficient in package management using the rpm command.

Linux Commands Cheat Sheet


Skills Graph

%%%%{init: {'theme':'neutral'}}%%%% flowchart RL linux(("`Linux`")) -.-> linux/UserandGroupManagementGroup(["`User and Group Management`"]) linux/UserandGroupManagementGroup -.-> linux/sudo("`Privilege Granting`") subgraph Lab Skills linux/sudo -.-> lab-422897{{"`Linux rpm Command with Practical Examples`"}} end

Understand the rpm Command and Its Use Cases

In this step, we will explore the rpm (Red Hat Package Manager) command, which is a powerful tool for managing packages in Linux distributions that use the RPM package format, such as CentOS, RHEL, and Fedora.

The rpm command allows you to perform various package management tasks, including:

  • Installing, upgrading, and removing RPM packages
  • Querying information about installed packages
  • Verifying the integrity of installed packages
  • Managing package dependencies

Let's start by understanding the basic 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 has a wide range of options and subcommands that allow you to perform various package management tasks. In the following steps, we will explore some of the most common use cases for the rpm command.

Install and Manage RPM Packages

In this step, we will learn how to install, upgrade, and remove RPM packages using the rpm command.

First, let's install a sample RPM package. We'll use the "htop" package, which is a popular interactive process viewer.

## 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 verify that the package was installed correctly:

## 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 newer version, we can use 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:

## Remove the htop package
sudo rpm -e htop

Example output:

Removed htop-3.0.5-1.el7.x86_64

In this step, you 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.

Perform RPM Package Queries and Verifications

In this step, we will learn how to perform various queries and verifications on installed RPM packages using the rpm command.

First, let's query the information of an installed package. We'll use the "bash" package as an example:

## 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:

## 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 shows any files in the coreutils package that have been modified since installation. The periods represent files that have not been modified, and the letters represent different types of changes (such as file permissions, ownership, or content).

Finally, let's query the list of files installed by a package. We'll use the "bash" package again:

## 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 step, you 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.

Summary

In this lab, we first explored the rpm (Red Hat Package Manager) command, which is a powerful tool for managing packages in Linux distributions that use the RPM package format. We learned that the rpm command allows us to perform various package management tasks, such as 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. Finally, we covered how to perform RPM package queries and verifications, which can be useful for troubleshooting and maintaining a healthy system.

Linux Commands Cheat Sheet

Other Linux Tutorials you may like