Oct 21, 2023 4 min read

RPM Command in Linux

Learn about rpm command in Linux with our step-by-step tutorial. The "rpm" command manages packages in Linux-based systems.

RPM Command in Linux
Table of Contents

Introduction

Before we discuss rpm command in Linux, let's first understand-What is rpm command ?

The RPM (Red Hat Package Manager) command is a package management utility used in Linux-based operating systems. It is primarily used by distributions that use the RPM package format, such as Red Hat Enterprise Linux (RHEL), CentOS, Fedora, and openSUSE. The RPM command allows users to manage software packages by installing, querying, verifying, and removing them.

In this tutorial, we will talk about how to install, update, uninstall, validate, query, and manage RPM packages, in general, using the rpm command. We will also address a few FAQs on rpm command in Linux.

Installing, Updating, and Removing RPM Packages

When working with Red Hat-based distributions, the yum or DNF commands are often used to install new packages because of their ability to find and install all necessary dependencies.

When possible, use yum or DNF instead of rpm to manage package installations, upgrades, and deletions.

An RPM package may be downloaded locally using a web browser or command-line tools like curl or wget before being installed.

It is important to use RPM packages that are compatible with your computer's architecture and CentOS distribution version. Take special caution when upgrading or replacing packages that are crucial to the operation of your systems, such as Glibc, systemd, or other system-wide services and libraries.

RPM packages may only be installed or removed by users with the root user account or the sudo user account.

By specifying the package name followed by the -i option, the rpm may be used to install it.

sudo rpm -ivh package.rpm

By using -v, rpm will provide a more detailed output, and by specifying -h, the hash-marked progress bar will be shown.

The rpm command may be used to install RPM packages without having to download them beforehand.

sudo rpm -ivh https://example.com/package.rpm

Use the -U option to upgrade an RPM package. If the package is not already installed, it will be:

sudo rpm -Uvh package.rpm

The rpm package manager will provide a list of all required but uninstalled packages if the one you are installing or upgrading relies on them. All required components must be downloaded and installed by hand.

Use the --nodeps option when installing an RPM package to avoid needing to have all of its dependencies already present on the system.

sudo rpm -Uvh --nodeps package.rpm

Use the -e option to erase (delete) an RPM package:

sudo rpm -e package.rpm

When you wish to uninstall a package yet keep its dependencies in place, the --nodeps option might be helpful:

sudo rpm -evh --nodeps package.rpm

With the --test option, you may instruct rpm to simulate an installation or uninstall. Just whether the order would be effective is shown.

sudo rpm -Uvh --test package.rpm

Querying RPM Packages

When the rpm command is given the -q option, it runs a query.

The rpm -q command may be used to search for a certain package by name and determine whether it is already installed. Run this command to see whether the OpenJDK 11 package is present on your machine:

sudo rpm -q java-11-openjdk-devel

You will see something similar if the package has been installed:

Output

java-11-openjdk-devel-11.0.4.11-0.el8_0.x86_64

To learn more about the package being questioned, pass -i:

sudo rpm -qi java-11-openjdk-devel

To get a list of every file in an RPM package that has been installed:

sudo rpm -ql package

To determine to which package an installed file belongs, type:

sudo rpm -qf /path/to/file

With the -a option, you may see a complete inventory of your system's packages:

sudo rpm -qa

Verifying RPM Packages

The rpm command's verification procedure involves checking the existence of all files installed by the package, as well as the file's digest, ownership, rights, etc.

The -V option may be used to ensure that a package installation was successful. To ensure the OpenLDAP package is legitimate, for instance, you would type:

sudo rpm -V openldap-2.4.46-9.el8.x86_64

If the check succeeds, the command will produce no output. If any of the checks fail, a failed test indicator will be shown.

Example output demonstrating modification to the file's mTime ("T"):

Output

.......T.  c /etc/openldap/ldap.conf

For information on what each character signifies, see the RMP man page.

Run the following command to confirm that all installed rpm packages are present:

sudo rpm -Va

FAQs on RPM Command in Linux

How does RPM differ from other package managers? 

RPM focuses on command-line utilities for package management. It is used by distributions like RHEL, CentOS, and Fedora.

What types of operations can I perform with the RPM command? 

With the RPM command, you can install, upgrade, query, verify, and remove software packages.

How can I install a package using RPM?

To install a package using RPM, run the command rpm -i <package_file.rpm>. Replace <package_file.rpm> with the actual package file name.

Can I install multiple packages simultaneously? 

Yes, you can install multiple packages in one command by specifying multiple package files, separated by spaces, after the rpm -i command.

How can I search for installed packages using RPM?

To search for installed packages, you can use the command rpm -qa | grep <package_name>. Replace <package_name> with the name or part of the name of the package you are searching for.

How can I query detailed information about a package using RPM? 

To view detailed information about a package, use the command rpm -qi <package_name>. Replace <package_name> with the name of the package you want to query.

Can I verify the integrity of an installed package using RPM?

Yes, you can verify the integrity of an installed package by using the command rpm -V <package_name>. This command checks the digital signature and compares the files' attributes with the RPM database records.

Conclusion

Installing, querying, verifying, updating, and uninstalling RMP packages may all be accomplished with the help of rpm, a command-line utility at a low abstraction level. Using yum or DNF installing RPM packages is recommended since they handle dependency resolution automatically.

Type man rpm into the terminal or go to RPM.org for a complete list of command options.

If you have any queries, please leave a comment below and we’ll be happy to respond to them.

Great! You’ve successfully signed up.
Welcome back! You've successfully signed in.
You've successfully subscribed to DevOps Blog - VegaStack.
Your link has expired.
Success! Check your email for magic link to sign-in.
Success! Your billing info has been updated.
Your billing was not updated.