20 Practical Examples of RPM Commands in Linux

RPM (Red Hat Package Manager) is a default open-source and widely-used package management utility for Red Hat-based systems such as CentOS Fedora, Rocky, and Alma Linux.

The rpm package management tool enables system administrators and users to install, update, uninstall, query, verify, and manage software packages on Unix/Linux operating systems, which formerly known as a .rpm file, contains compiled software programs and libraries required by the packages.

This article provides 20 useful examples of RPM commands that might be helpful to you. With the help of these RPM commands, you can manage the installation, updating, and removal of packages on your Linux systems.

RPM Facts

Here are some facts about RPM (Red Hat Package Manager):

  • RPM is freely available and released under the General Public License (GPL).
  • RPM maintains a database of all installed packages, storing this information in the /var/lib/rpm directory.
  • RPM serves as the primary method for installing packages on Linux systems. If packages have been installed using source code, RPM does not manage them.
  • RPM operates with .rpm files, containing vital package information such as its identity, source, dependencies, version details, and more.

Basic Modes for RPM Command

Here are the primary modes for the RPM command:

  • Install – The rpm -i command installs a new package on the system.
  • Upgrade – The rpm -U command upgrades an existing package to a newer version.
  • Remove – The rpm -e command uninstalls or removes a package from the system.
  • Query – The rpm -q command queries the RPM database for information about installed packages.
  • Verify – The rpm -V command verifies the integrity of installed package files.
  • Freshen – The rpm -F command upgrades or installs a package only if it is already installed.
  • Rebuild Database – The rpm --rebuilddb command rebuilds the RPM database, resolving database corruption issues.
  • Import GPG Key – The rpm --import command imports a GPG key used for package signature verification.
  • Query All – The rpm -qa command lists all installed packages on the system.
  • Query Files – The rpm -ql command lists all files installed by a specific package.
  • Query Documentation – The rpm -qd command lists documentation files provided by a package.
  • Query Dependencies – The rpm -qR command lists runtime dependencies for a package.
  • Query Provides – The rpm -q --provides command lists capabilities provided by a package.
  • Query Requires – The rpm -q --requires command lists dependencies required by a package.

Where to Find RPM Packages

You can find RPM packages in several places, depending on your Linux distribution. Here are common locations where you can find and download all RPM packages.

Please remember you must be a root user when installing packages in Linux, with the root privileges you can manage rpm commands with their appropriate options.

1. How to Check RPM Package Signature

Always check the PGP signature of packages before installing them on your Linux systems and make sure their integrity and origin are OK.

Use the following command with --checksig (check signature) option to check the signature of a package called hardinfo.

rpm --checksig hardinfo-2.0.11-FedoraLinux-39.x86_64.rpm

hardinfo-2.0.11-FedoraLinux-39.x86_64.rpm: digests OK

2. How to Install RPM Package

To install an RPM software package, use the following command with -ivh option, which will install the rpm package called hardinfo-2.0.11-FedoraLinux-39.x86_64.rpm on a Linux system.

rpm -ivh hardinfo-2.0.11-FedoraLinux-39.x86_64.rpm

Verifying...                          ################################# [100%]
Preparing...                          ################################# [100%]
Updating / installing...
   1:hardinfo-2.0.11-1                ################################# [100%]

Let’s break down the components of the above command:

  • -i : install a package
  • -v : verbose for a nicer display
  • -h: print hash marks (#) to show the progress of the installation.

3. How to Check Dependencies of RPM Package Before Installing

Let’s say you would like to do a dependency check before installing or upgrading a package. For example, use the following command to check the dependencies of hardinfo-2.0.11-FedoraLinux-39.x86_64.rpm package.

The command queries and displays the runtime dependencies required by the “hardinfo” package, which helps to identify and ensure that all necessary dependencies are met before installing the package.

rpm -qpR hardinfo-2.0.11-FedoraLinux-39.x86_64.rpm
 
libX11.so.6()(64bit)
libatk-1.0.so.0()(64bit)
libc.so.6()(64bit)
libc.so.6(GLIBC_2.14)(64bit)
libc.so.6(GLIBC_2.2.5)(64bit)
libc.so.6(GLIBC_2.3)(64bit)
libc.so.6(GLIBC_2.33)(64bit)
libc.so.6(GLIBC_2.34)(64bit)
libc.so.6(GLIBC_2.38)(64bit)
libc.so.6(GLIBC_2.7)(64bit)
libcairo-gobject.so.2()(64bit)
libcairo.so.2()(64bit)
...

Let’s break down the components of the above command:

  • -q : Query a package.
  • -p : List capabilities this package provides.
  • -R : List capabilities on which this package depends.

4. How to Install RPM Package Without Dependencies

To install an rpm package without dependencies, you can use --nodeps option, which will forcefully install an RPM package without checking or resolving dependencies.

rpm -ivh --nodeps hardinfo-2.0.11-FedoraLinux-39.x86_64.rpm

The above command forcefully installs the rpm package by ignoring dependencies errors, but if those dependency files are missing, then the program will not work at all until you install them.

5. How to Check Installed RPM Package

To check an installed rpm package, you can use -q option, which will query and display information about the installed version of the package.

rpm -q hardinfo

hardinfo-2.0.11-1.x86_64

6. How to Find Where RPM Files are Installed

To view all the files of an installed rpm package, use the -ql (query list) with rpm command.

rpm -ql hardinfo

/usr/bin/hardinfo2
/usr/lib/.build-id
/usr/lib/.build-id/3a
/usr/lib/.build-id/53
/usr/lib/.build-id/7c
/usr/lib/.build-id/ba
/usr/lib/.build-id/e0
/usr/lib64/hardinfo2
/usr/lib64/hardinfo2/modules
/usr/lib64/hardinfo2/modules/benchmark.so
/usr/lib64/hardinfo2/modules/computer.so
/usr/lib64/hardinfo2/modules/devices.so
/usr/lib64/hardinfo2/modules/network.so
...

7. How to List Recently Installed RPM Packages

Use the following rpm command with -qa (query all) option, will list all the recently installed rpm packages.

rpm -qa --last


hardinfo-2.0.11-1.x86_64                      Mon 04 Mar 2024 01:32:14 PM IST
pipewire-pulseaudio-1.0.3-1.fc39.x86_64       Mon 04 Mar 2024 01:32:02 PM IST
pipewire-jack-audio-connection-kit-1.0.3-1.fc39.x86_64 Mon 04 Mar 2024 01:32:02 PM IST
pipewire-alsa-1.0.3-1.fc39.x86_64             Mon 04 Mar 2024 01:32:02 PM IST
libsoup-devel-2.74.3-3.fc39.x86_64            Mon 04 Mar 2024 01:32:02 PM IST
json-glib-devel-1.8.0-1.fc39.x86_64           Mon 04 Mar 2024 01:32:02 PM IST
gtk3-devel-3.24.41-1.fc39.x86_64              Mon 04 Mar 2024 01:32:02 PM IST
xdg-desktop-portal-gtk-1.15.1-1.fc39.x86_64   Mon 04 Mar 2024 01:32:01 PM IST
xdg-desktop-portal-1.18.2-1.fc39.x86_64       Mon 04 Mar 2024 01:32:01 PM IST
libcanberra-gtk3-0.30-32.fc39.x86_64          Mon 04 Mar 2024 01:32:01 PM IST
gtk3-3.24.41-1.fc39.x86_64                    Mon 04 Mar 2024 01:32:01 PM IST
...

8. How to List All Installed RPM Packages

Type the following command to print all the names of installed packages on your Linux system.

rpm -qa

fonts-filesystem-2.0.5-12.fc39.noarch
libreport-filesystem-2.17.11-3.fc39.noarch
hunspell-filesystem-1.7.2-5.fc39.x86_64
abattis-cantarell-vf-fonts-0.301-10.fc39.noarch
fedora-gpg-keys-39-1.noarch
fedora-repos-39-1.noarch
setup-2.14.4-1.fc39.noarch
filesystem-3.18-6.fc39.x86_64
basesystem-11-18.fc39.noarch
default-fonts-core-sans-4.0-9.fc39.noarch
langpacks-fonts-en-4.0-9.fc39.noarch
...

9. How to Upgrade a RPM Package

If we want to upgrade any RPM package “–U” (upgrade) option will be used. One of the major advantages of using this option is that it will not only upgrade the latest version of any package, but it will also maintain the backup of the older package so that in case if the newer upgraded package does not run the previously installed package can be used again.

rpm -Uvh hardinfo-2.0.11-FedoraLinux-39.x86_64.rpm

10. How to Remove a RPM Package

To un-install an RPM package, for example, we use the package name hardinfo, not the original package name hardinfo-2.0.11-FedoraLinux-39.x86_64.rpm. The -e (erase) option is used to remove the package.

rpm -evv hardinfo

11. How to Remove an RPM Package Without Dependencies

The --nodeps (do not check dependencies) option forcefully remove the rpm package from the system. But keep in mind removing a particular package may break other working applications.

rpm -ev --nodeps hardinfo

12. How to Find RPM Package of a Specific File

Let’s say, you have a list of files and you would like to find out which package belongs to these files. For example, the following command with -qf (query file) option will show you a file /usr/bin/htpasswd that is owned by package httpd-tools-2.4.58-1.fc39.x86_64.

rpm -qf /usr/bin/htpasswd

httpd-tools-2.4.58-1.fc39.x86_64

13. How to Query Information of Installed RPM Package

Let’s say you have installed an rpm package and want to know the information about the package. The following -qi (query info) option will print the available information of the installed package.

rpm -qi hardinfo

Name        : hardinfo
Version     : 2.0.11
Release     : 1
Architecture: x86_64
Install Date: Mon 04 Mar 2024 01:32:14 PM IST
Group       : unknown
Size        : 5174404
License     : GPL2+
Signature   : (none)
Source RPM  : hardinfo-2.0.11-1.src.rpm
Build Date  : Sat 02 Mar 2024 06:37:42 AM IST
Build Host  : fedora.bigbear.dk
Relocations : /usr 
Vendor      : Humanity
URL         : https://www.hardinfo2.org
Summary     : hardinfo2 built using CMake
Description :
Hardinfo2 is a small application that displays information about your hardware and operating system.  It has online benchmarking to check your machine performance against other machines.

14. Get the Information of RPM Package Before Installing

You have downloaded a package from the internet and want to know the information of a package before installing. For example, the following option -qip (query info package) will print the information of a package sqlbuddy.

rpm -qip sqlbuddy

Name        : sqlbuddy                     Relocations: (not relocatable)
Version     : 1.3.3                        Vendor: (none)
Release     : 1                            Build Date: Wed 02 Nov 2011 11:01:21 PM BDT
Install Date: (not installed)              Build Host: rpm.bar.baz
Group       : Applications/Internet        Source RPM: sqlbuddy-1.3.3-1.src.rpm
Size        : 1155804                      License: MIT
Signature   : (none)
Packager    : Erik M Jacobs
URL         : http://www.sqlbuddy.com/
Summary     : SQL Buddy â Web based MySQL administration
Description : SQLBuddy is a PHP script that allows for web-based MySQL administration.

15. How to Query Documentation of Installed RPM Package

To get the list of available documentation of an installed package, use the following command with the option -qdf (query document file) will display the manual pages related to the vmstat package.

rpm -qdf /usr/bin/vmstat

/usr/share/doc/procps-ng/AUTHORS
/usr/share/doc/procps-ng/FAQ
/usr/share/doc/procps-ng/NEWS
/usr/share/doc/procps-ng/README.md
/usr/share/doc/procps-ng/bugs.md
/usr/share/man/man1/free.1.gz
/usr/share/man/man1/pgrep.1.gz
...

16. How to Verify a RPM Package

Verifying a package compares the information of installed files of the package against the rpm database. The -Vp (verify package) is used to verify a package.

rpm -Vp sqlbuddy-1.3.3-1.noarch.rpm

S.5....T.  c /etc/httpd/conf.d/sqlbuddy.conf

17. How to Verify all RPM Packages

Type the following command to verify all the installed rpm packages.

rpm -Va

S.5....T.  c /etc/rc.d/rc.local
.......T.  c /etc/dnsmasq.conf
.......T.    /etc/ld.so.conf.d/kernel-2.6.32-279.5.2.el6.i686.conf
S.5....T.  c /etc/yum.conf
S.5....T.  c /etc/yum.repos.d/epel.repo

18. How to Import an RPM GPG Key

To verify RHEL/CentOS/Fedora packages, you must import the GPG key. To do so, execute the following command. It will import the CentOS 8 GPG key.

rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-8

19. How to List all Imported RPM GPG Keys

To print all the imported GPG keys in your system, use the following command.

rpm -qa gpg-pubkey*

gpg-pubkey-0608b895-4bd22942
gpg-pubkey-7fac5991-4615767f
gpg-pubkey-0f2672c8-4cd950ee
gpg-pubkey-c105b9de-4e0fd3a3
gpg-pubkey-00f97f56-467e318a
gpg-pubkey-6b8d79e6-3f49313d
gpg-pubkey-849c449f-4cb9df30

20. How To Rebuild Corrupted RPM Database

Sometimes rpm database gets corrupted and stops all the functionality of rpm and other applications on the system. So, at this time we need to rebuild the rpm database and restore it with the help of the following command.

cd /var/lib
rm __db*
rpm --rebuilddb
rpmdb_verify Packages

In conclusion, the presented rpm commands provide a comprehensive guide for efficiently managing software packages on RHEL-based Linux distributions.

Hey TecMint readers,

Exciting news! Every month, our top blog commenters will have the chance to win fantastic rewards, like free Linux eBooks such as RHCE, RHCSA, LFCS, Learn Linux, and Awk, each worth $20!

Learn more about the contest and stand a chance to win by sharing your thoughts below!

Ravi Saive
I am an experienced GNU/Linux expert and a full-stack software developer with over a decade in the field of Linux and Open Source technologies

Each tutorial at TecMint is created by a team of experienced Linux system administrators so that it meets our high-quality standards.

Join the TecMint Weekly Newsletter (More Than 156,129 Linux Enthusiasts Have Subscribed)
Was this article helpful? Please add a comment or buy me a coffee to show your appreciation.

44 Comments

Leave a Reply
  1. $ which rpmdb_verify
    

    /usr/bin/which: no rpmdb_verify in (/usr/share/Modules/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin)

    RPMDB(8)
    (…)
    rpm {–initdb|–rebuilddb} [-v] [–dbpath DIRECTORY] [–root DIRECTORY]
    (…)
    Red Hat, Inc 29 June 2010

    $ cat /etc/redhat-release
    
    Fedora release 29 (Twenty Nine)
    
    Reply
  2. How to rebuild corrupted RPM Database needs correction, the directory is /var/lib/rpm rather than /var/lib for removal of __db files

    Reply
    • @Atul,

      To rebuild corrupted RPM database, fir remove /var/lib/rpm/__db* files to avoid stale locks.

      # cd /var/lib
      # rm __db*
      

      After that Rebuild RPM database using following commands.

      # rpm --rebuilddb
      # rpmdb_verify Packages
      
      Reply
  3. Verify : It is used to query about different RPM packages.
    Query : It is used for the verification of any RPM package.

    It seems you have interchanged the definitions of Verify and Query.

    Reply
  4. Hello,
    Can you please let me know “How to find which package/packages is recently uninstalled from linux (RHEl/centos) system?”

    Thank you.

    Reply
    • @Sandeep,

      Really good question, never thought of having an auto update for security packages, but will look surely write a detailed guide on how to install on security updates in Linux, just stay tuned for this article, will push soon..

      Reply
  5. Hi,

    I have several rpm packages present in different folder, say 2 RPM files per folder, and total 70 folders are there like this.

    I need to install all the rpm’s which are present in different folder in single shot.

    how to do this, please suggest

    Reply
  6. As root user , I installed a package using rpm -ivh . All the files and folders are with a user:group which i don’t want.
    How can i install with specific user:group?

    Reply
    • @Naresh,

      That’s not possible, you can’t install packages with specific user permission, and in Linux only root or sudo privileged user can install packages with its own permission, yes but you change the ownership to whatever user only after installation of packages..

      Reply
      • You can use “rpm2cpio | cpio -dium” to extract the content of an RPM to the current directory. The files are owned by the current user and most of the extracted binaries can be used by adding lib directories to LD_LIBRARY_PATH (export LD_LIBRARY_PATH=”${LD_LIBRARY_PATH}:${PWD}/usr/lib:${PWD}/usr/lib64“).

        Reply
    • @Naresh,

      Sorry your question is not clear to me, what you trying to say? you mean to have a log for all installed RPM files? If yes, then you should look for yum-utils tools that will provide more information about RPM packages..

      Reply
  7. Q : how to automatically install dependencies of installing rpm package?? if one rpm package requires 10 dependencies then I need to download 10 dependencies separately?

    Reply
  8. Add RPM hack for listing URL of RPMs we need in one app. Like apt-get –print-uris plus cut and grep so we can download the package in another computer with download manager (wget, IDM, etc.). Thank you.

    Reply
  9. Pls let me know if there is a way to download and install a package from a url?

    I am trying to install cntlm on centos6.2 but the website is asking me to first download the package, then transfer it to the linux machine and then install it.

    Reply
  10. how to install redhat 6 from windows 8…. when i used to install it.. i ddnt get booting option lyk windows.. its shows me some error…. is it possible to install??? bt my neighbour told me tht cnt to install redhat 6 from windows 8… is tht real???

    Reply
  11. @Lemming:

    rpm is incapable of that. The second facts states “RPM keeps the information of all the installed packages”. You can however still get the information:

    yum provides “*/wm”

    If you want to know the package for a really specific command, replace the asteriks with the full path.

    Reply
  12. The holy grail is missing.

    How to find out which _non-installed_ package provides a certain command.
    E.g. I’m looking for the package that provides the command `wm` which is apparently part of tcl/tk. I couldn’t find it yet. And googling for wm is not very helpful…

    Reply
  13. Ravi , I have used yum clean all , and when I tried to update the yum its giving error

    [root@machine8 6]# yum update
    Loaded plugins: fastestmirror, refresh-packagekit, security
    Loading mirror speeds from cached hostfile
    Could not get metalink https://mirrors.fedoraproject.org/metalink?repo=epel-6&arch=x86_64 error was
    16: error opening local file from https://mirrors.fedoraproject.org/metalink?repo=epel-6&arch=x86_64, IOError: [Errno 22] invalid mode (‘wb’) or filename: ‘/var/cache/yum/x86_64/6/epel/metalink.xml.tmp’

    [Errno 22] invalid mode (‘w’) or filename: ‘/var/cache/yum/x86_64/6/extras/mirrorlist.txt’

    how can I correct this ?

    Reply
  14. you have the query and verify short descriptions flip-floppped.

    Verify : It is used to query about different RPM packages.
    Query : It is used for the verification of any RPM package.

    Other than that, super helpful for a guy moving from Solaris to Linux as my primary OS to support!

    Reply

Got Something to Say? Join the Discussion...

Thank you for taking the time to share your thoughts with us. We appreciate your decision to leave a comment and value your contribution to the discussion. It's important to note that we moderate all comments in accordance with our comment policy to ensure a respectful and constructive conversation.

Rest assured that your email address will remain private and will not be published or shared with anyone. We prioritize the privacy and security of our users.