The RPM Package Manager (RPM) is an open packaging system used in Red Hat Linux and its distributions such as CentOS and Fedora. An RPM Package contains archive files and metadata including dependencies and installs location.
An RPM package has a
.rpm file format. rpm command is used to install, update, remove, verify, query, and manage RPM packages.
This tutorial will demonstrate different examples of rpm commands in RHEL-based Linux systems.
For this tutorial, you will need:
a. A RHEL system with access to sudoers account or root account
b. An RPM package
An RPM package comes with this naming format.
You can download RPM packages from the website or use
dnf command to get the package from the terminal.
The following command downloads the
curl package in the current directory
$ sudo dnf install curl --downloadonly --downloaddir=/home/linuxwizardry
ls command to view files that are downloaded.
[[email protected] ~]$ ls curl-7.76.1-18.el9.x86_64.rpm libcurl-7.76.1-18.el9.x86_64.rpm
How to use the rpm command
The syntax for using the rpm command is as follows:
$ sudo rpm option package_name
Some common options in rpm command are:
-q: query a package
-i: install a package
-U: upgrade a package
-e: uninstall a package
-R: List dependencies of a package
-v: display verbose information
-h: print hash symbols as the package archive is unpacked
1. Display the information of an RPM package
You can view the information of an RPM package using the
-qip option with
$ sudo rpm -qip package.rpm
For example, the following command displays the information about
2. Install an RPM package
rpm command with
-i flag is used to install an RPM package on the system. The specified package must be available in the directory.
$ sudo rpm -ivh package.rpm
-vh option helps to display the verbose information with
# symbols indicating the archived package is unpacked.
3. Query an installed RPM package
You can get the information about an installed RPM package using the
$ sudo rpm -qi package_name
4. Upgrade an RPM package
You can upgrade your installed RPM package to the latest version with the
-U option. It removes the older version and installs the newest version of the package.
The following command upgrades the package to the latest version.
$ sudo rpm -Uvh package_name
5. Removing an RPM package
-e option is used to remove the installed RPM package from the system. You have to specify the package name instead of the
.rpm package name.
This command uninstalls the
htop package in the system.
$ sudo rpm -evh htop
6. Check dependencies of RPM Package
You can view the dependencies of an RPM package using
$ sudo rpm -qpR package_name
For instance, the following command lists all dependencies of the package
$ sudo rpm -qpR curl-7.76.1-18.el9.x86_64.rpm
7. Install RPM package without dependencies
--nodeps option tells the rpm command to not verify package dependencies before installing or upgrading. It avoids the dependencies check and installs an RPM package without dependencies.
$ sudo rpm -ivh --nodeps htop-3.3.1-1.el9.x86_64.rpm
Note: This is not recommended as it ignores dependencies errors and forcefully installs the rpm package. The program will not run due to missing dependencies.
8. Remove RPM package without dependencies
Similarly, you can use
--nodeps option with
-e option to remove an RPM package without dependencies.
The following command erases the package
nx-libs from the system without its dependencies.
$ sudo rpm -evh --nodeps nx-libs
9. View all files of an installed RPM package
You can view a list of all files in the RPM package using
This command prints all files associated with the installed package
htop in the system.
$ sudo rpm -ql htop
10. Display all installed RPM packages
-qa option with the rpm command prints the list of all installed RPM packages in the system.
$ sudo rpm -qa
11. Display recently installed RPM packages only
--order option sorts the list of installed RPM packages by install time in descending order. You can run the following command to get a list of recently installed RPM packages.
$ sudo rpm -qa --last
12. Check signatures in the RPM package
--checksig option checks the digests and digital signatures in the package file to verify the integrity and origin of the package.
$ sudo rpm --checksig package_name
As you can see in the output, both packages have their digests signatures OK and are verified successfully.
13. Query a file to find its RPM package
You can also use the rpm command to query a file and find the package that belongs to the given file.
$ sudo rpm -qf package_name
14. Verify the RPM package
-V option helps to verify the RPM package against the rpm database. It compares information of the installed files in the package with information of files taken from the package metadata stored in the rpm database.
$ sduo rpm -Vp package_name
15. Verify all RPM packages
You can run the following command to verify all installed RPM packages in the system.
$ sudo rpm -Va
16. Import an RPM GPG key
--import option allows you to import the GPG key manually. RPM GPG key files can be found in the
The command below import EPEL 9 GPG key.
$ sudo rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
17. List all Imported RPM GPG keys
To get a list of all imported RPM GPE keys in your system, run the command below.
$ sudo rpm -qa gpg-pubkey*
18. Query documentation of installed RPM package
-qdf option prints the list of available documentation of the installed RPM package.
This command lists the documentation file related to dnf package.
$ sudo rpm -qdf /usr/bin/dnf
Now you know how to use the rpm command to manage RPM packages in RHEL-based Linux systems. rpm is a powerful and handy tool for managing RPM packages. We discussed several examples of rpm commands that can be used to install, update, query, remove and verify RPM packages.
We hope this tutorial has helped you to understand the rpm command in Linux. If you have any questions or feedback, please let us know in the comment section.