rpm Command: Syntax, Options, Examples

Introduction

rpm is a command-line utility for managing packages on Unix/Linux systems. It allows you to install, query, update, verify, and remove .rpm packages.

The tool is the default package manager for Red Hat-based systems and only works with the .rpm format.

In this article, you will learn everything about the rpm command, its syntax, options, and use cases via practical examples.

 rpm Command: Syntax, Options, Examples

Prerequisites

  • A system running Linux (this tutorial uses Rocky Linux 9).
  • Access to the command line/terminal.
  • Access to root or an account with sudo privileges.

rpm Command Syntax

The basic syntax for the command is:

sudo rpm [option] [package_name]

The rpm command does not work independently and must be used with options and package names.

rpm Command Options

The rpm command has plenty of options that modify how it works. The table below shows the most popular command options used with rpm.

-e, --eraseRemoves a package.
-h, --hashPrints a progress bar (hash marks) as the package installs.
-i, --installInstalls a package.
-l, --listLists files in a package.
-q, --queryQueries a package.
-s, --stateDisplays the state of the listed files.
-U, --upgradeUpgrades a package.
-v, --verboseProvides more detailed output.
-V, --verifyVerifies the integrity of installed packages.
-F, --freshenUpgrades a package only if an older version is already installed.
-qf, --queryformatSpecifies the format for package queries.
--nodepsSkips dependency checks during installation or removal.
--forceForces installation or removal, ignoring warnings and dependency issues.
--testPerforms a test run without actually installing or removing packages.
--importImports a GPG key for verifying package signatures.
--setpermsSets permissions for installed files based on package specifications.

rpm Command Examples

The rpm command is simple to use and allows combining multiple options to customize each query. The following text presents the most common use cases.

Install .rpm Packages

To install .rpm packages with the rpm command, use the syntax:

sudo rpm -ivh [package_name]

The command includes the options:

  • -i - Installs packages.
  • -h - Prints hash marks, which are visual indicators that show the installation process progress.

The package has to be compatible with the machine system architecture. For instance, download the MySQL package with:

wget https://dev.mysql.com/get/mysql84-community-release-el9-1.noarch.rpm
wget mysql terminal output

Note: To download packages, use the curl or wget command.

Next, install the MySQL package:

 sudo rpm -ivh mysql84-community-release-el9-1.noarch.rpm
terminal output for rpm -ivh

Upgrade .rpm Packages

rpm upgrades a package by uninstalling the current version and installing the latest one. The command for upgrading a package is:

sudo rpm -Uvh [package_name]

The command consists of:

  • -U - Upgrades packages.
  • -v - Shows verbose mode.
  • -h - Prints hash marks to show the upgrading process.

To upgrade MySQL, use:

sudo rpm -Uvh mysql84-community-release-el9-1.noarch.rpm
terminal output for rpm -uvh

If the new version requires additional dependencies, install them manually. After running the command, rpm lists the missing dependencies.

To ignore the message and update without the dependencies, add the --nodeps option to the command:

sudo rpm -Uvh --nodeps package_name

Remove .rpm Packages

Remove .rpm packages using the -e (--erase) option:

sudo rpm -e [package_name]

For example, to remove MySQL, run:

sudo rpm -e mysql84-community-release-el9-1

The command has no output.

Display Package Information After Installing

To see available information about an installed .rpm package, use the -qi option:

sudo rpm -qi [package_name]

To do so for MySQL, run:

sudo rpm -qi mysql84-community-release-el9-1.noarch.rpm
terminal output for rpm -qi

Display Package Information Before Installing

The command for displaying information about a package prior to installation is:

sudo rpm -qip [package_name]

The command includes the options:

  • -qi - Queries information.
  • -p - Verifies a package.

To display information before installing the MySQL package, use the command:

sudo rpm -qip mysql84-community-release-el9-1.noarch.rpm
terminal output for rpm -qip

Check Package Dependencies Before Installing

rpm allows you to check the packages' dependencies before installing them on a system. However, you need to have the .rpm package downloaded locally to see a list of dependencies.

The command for doing so is:

rpm -qpR [package_name]

The options are:

  • -q - Queries format.
  • -p - Verifies a package.
  • -R - Lists package dependencies.

For example, to list the MySQL package dependencies, run:

rpm -qpR mysql84-community-release-el9-1.noarch.rpm
terminal output for sudo rpm -qdR

List All Files of an Installed Package

To list all package files, use rpm with the -ql option:

sudo rpm -ql [package_name]

For example, to list files of the MySQL package, run:

sudo rpm -ql mysql84-community-release-el9-1.noarch.rpm
terminal output for sudo rpm -ql

List Installed Packages

To list all installed .rpm packages on the system, use this command:

sudo rpm -qa
sudo rpm -qa terminal output

List Recently Installed Packages

To display a list of all the recently installed packages, use the -qa (query all) option along with the --last attribute:

sudo rpm -qa --last
rpm -qa --last terminal output

The output lists all the installed RPM packages, ordering them by the latest package on top.

Where to Find and Download .rpm Packages?

You can find and download .rpm packages from various sources, including official repositories, third-party repositories, and direct download links provided by software vendors.

Online package repositories like RPMFind.net, RPM Pbone, and FreshRPMs offer searchable databases of .rpm packages for download.

Conclusion

This article showed how to use the rpm command to install, verify, upgrade, and delete packages.

Next, learn how to install .rpm files on different Linux distributions.

Was this article helpful?
YesNo
Sara Zivanov
Sara Zivanov is a technical writer at phoenixNAP who is passionate about making high-tech concepts accessible to everyone. Her experience as a content writer and her background in Engineering and Project Management allows her to streamline complex processes and make them user-friendly through her content.
Next you should read
Snap vs APT: What's the Difference?
January 21, 2021

The software in Linux is traditionally organized in repositories that contain applications and all the dependencies...
Read more
How to List Installed Packages on CentOS with Yum or RPM
April 29, 2019

Managing a CentOS operating system often means knowing the software packages...
Read more
How to Uninstall or Remove Packages from CentOS
October 4, 2019

Once you have installed a package, it may be necessary to find and remove unneeded software and...
Read more
How to List Installed Packages on Ubuntu
March 9, 2022

Having a precise list of installed packages helps system admins maintain, replicate, and reinstall systems...
Read more