rpm Command in Linux: Install, Query, and Verify Packages

By 

Updated on

6 min read

RPM Command

The RPM Package Manager (RPM) is a powerful package management system used by Red Hat Enterprise Linux, Fedora, AlmaLinux, Rocky Linux, and their derivatives. RPM also refers to the rpm command and .rpm file format. An RPM package consists of an archive of files and metadata including information such as dependencies and install location.

In this tutorial, we will talk about how to use the rpm command to install, update, remove, verify, query, and otherwise manage RPM packages.

Installing, Updating and Removing RPM Packages

On modern Red Hat based distributions, you will use dnf to install packages from repositories — it resolves and installs all dependencies automatically. On older RHEL 7 systems, yum serves the same purpose.

You should always prefer using dnf (or yum on RHEL 7) over rpm when installing, updating, and removing packages.

Before installing an RPM package, you must first download the package on your system using a browser or command-line tools like curl or wget .

When installing RPM packages, make sure they are built for your system architecture and distribution version. Be extra careful when replacing or updating important system packages, like glibc, systemd, or other services and libraries that are essential for the proper functioning of your system.

Only root or users with sudo privileges can install or remove RPM packages.

To install an RPM package with the rpm, use the -i option, followed by the package name:

Terminal
sudo rpm -ivh package.rpm

The -v option tells rpm to show verbose output and the -h option to show the hash marked progress bar.

It is safer to download the RPM file first and then install it locally. For example:

Terminal
curl -O https://example.com/package.rpm
sudo rpm -ivh package.rpm

To upgrade an RPM package, use the -U option. If the package is not installed it will be installed:

Terminal
sudo rpm -Uvh package.rpm

If the package you are installing or updating depends on other packages that are not currently installed, rpm will display a list of all missing dependencies. You will have to download and install all dependencies manually.

To install an RPM package without having all the required dependencies installed on the system, use the --nodeps option:

Terminal
sudo rpm -Uvh --nodeps package.rpm

To remove (erase) an RPM package, use the -e option followed by the installed package name (not the .rpm filename):

Terminal
sudo rpm -e package-name

The --nodeps option is also useful when you want to remove a package without checking its dependencies:

Terminal
sudo rpm -e --nodeps package-name

The --test option tells rpm to run the installation or removal command without actually doing anything. It only shows whether the command would work or not:

Terminal
sudo rpm -Uvh --test package.rpm

Querying RPM Packages

The -q option tells the rpm command to run a query.

To query (search) whether a certain package is installed, pass the package name to the rpm -q command. The following command will show you whether the OpenJDK 11 package is installed on the system:

Terminal
rpm -q java-11-openjdk-devel

If the package is installed you will see something like this:

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

Query an Uninstalled RPM File

You can inspect an RPM file before installing it. To show package information from a local file, use:

Terminal
rpm -qpi package.rpm

To list the files contained in the package without installing it, use:

Terminal
rpm -qpl package.rpm

Pass -i to get more information about the queried package:

Terminal
rpm -qi java-11-openjdk-devel

To get a list of all the files in an installed RPM package:

Terminal
rpm -ql package-name

If you want to find out which installed package a particular file belongs to, type:

Terminal
rpm -qf /path/to/file

To get a list of all installed packages on your system use the -a option:

Terminal
rpm -qa

Verifying RPM Packages

When verifying a package, the rpm command checks whether each file installed by a package exists on the system, the file’s digest, ownership, permissions, etc.

To verify an installed package, use the -V option. For example, to verify the openldap package you would run:

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

If the verification passes the command will not print any output. Otherwise, if some of the checks fail, it will show a character that indicates the failed test.

For example, the following output shows that the file’s mTime has been changed (“T”):

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

Refer to the RPM man page about what each character means.

To verify all the installed RPM packages run the following command:

Terminal
rpm -Va

Troubleshooting

Failed dependencies error
The package requires other packages that are not installed. Prefer using dnf install package.rpm so dependencies are resolved automatically instead of forcing installation with --nodeps.

Package is not installed
Check the exact package name with rpm -qa | grep name, then rerun the query or removal command with the installed package name rather than the RPM filename.

Signature or digest check fails
Verify the package source and make sure the appropriate GPG keys are installed. You can inspect signature information with rpm -K package.rpm.

Cannot find which package owns a file
Use the full absolute path with rpm -qf /path/to/file. If nothing is returned, the file may not belong to an installed RPM package.

Quick Reference

CommandDescription
rpm -ivh package.rpmInstall a package
rpm -Uvh package.rpmInstall or upgrade a package
rpm -e package-nameRemove a package
rpm -Uvh --nodeps package.rpmInstall ignoring dependency checks
rpm -Uvh --test package.rpmTest install without making changes
rpm -q package-nameCheck if a package is installed
rpm -qi package-nameShow detailed package information
rpm -ql package-nameList all files in a package
rpm -qf /path/to/fileFind which package owns a file
rpm -qaList all installed packages
rpm -V package-nameVerify an installed package
rpm -VaVerify all installed packages

FAQ

What is the difference between rpm and dnf?
dnf (and yum on older systems) installs packages from repositories and resolves dependencies automatically. rpm is a lower-level tool that works with individual .rpm files and does not resolve dependencies — you have to handle them manually.

How do I find which package provides a specific file?
Use rpm -qf /path/to/file to identify the installed package that owns a given file. For example, rpm -qf /usr/bin/python3 will show the package that installed the Python 3 binary.

How do I list all installed RPM packages?
Run rpm -qa to print the full list. To filter it, pipe the output to grep — for example, rpm -qa | grep nginx.

Can I install an RPM without downloading it first?
It is better to download the package first and then install it locally. That gives you a chance to verify the file and avoids relying on URL handling behavior that may vary between environments.

Conclusion

rpm is a low-level command-line tool for installing, querying, verifying, updating, and removing RPM packages. When installing RPM packages, prefer using dnf as it automatically resolves all dependencies for you.

For more information about all available command options type man rpm in your terminal or visit the RPM.org website.

Linuxize Weekly Newsletter

A quick weekly roundup of new tutorials, news, and tips.

About the authors

Dejan Panovski

Dejan Panovski

Dejan Panovski is the founder of Linuxize, an RHCSA-certified Linux system administrator and DevOps engineer based in Skopje, Macedonia. Author of 800+ Linux tutorials with 20+ years of experience turning complex Linux tasks into clear, reliable guides.

View author page