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.
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 , --erase | Removes a package. |
-h , --hash | Prints a progress bar (hash marks) as the package installs. |
-i , --install | Installs a package. |
-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. |
-F , --freshen | Upgrades a package only if an older version is already installed. |
-qf , --queryformat | Specifies the format for package queries. |
--nodeps | Skips dependency checks during installation or removal. |
--force | Forces installation or removal, ignoring warnings and dependency issues. |
--test | Performs a test run without actually installing or removing packages. |
--import | Imports a GPG key for verifying package signatures. |
--setperms | Sets 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.
-v
- Shows verbose output.
-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
Next, install the MySQL package:
sudo rpm -ivh mysql84-community-release-el9-1.noarch.rpm
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
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
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
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
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
List Installed Packages
To list all installed .rpm packages on the system, use this command:
sudo rpm -qa
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
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.