The Most Commonly Used RPM Commands in Linux With Examples

commonly used RPM commands

In this article, we will review the most commonly used RPM commands in Linux. These commands play a pivotal role in package management, allowing users to install, update, query, and manage software packages seamlessly on their Linux systems.

Table of Contents

Introduction

In this article, we will review the most commonly used RPM commands in Linux. Every systems administrator should be familiar with most if not all of these commands. In addition, we will review commonly used RPM commands that address the following five RPM modes: Installing, removing, upgrading, verifying, and querying.

Brief History

Red Hat Package Manager or RPM Package Manager (RPM) as it is now known, is an open-source package management system originally developed for Red Hat in the late 90s by software engineer and founder Marc Ewing along with Eric Troan and Jeff Johnson.
Red Hat Founders

Adapted from The Irish Times website – Red Hat Founder Marc Ewing (right) and co-founder Robert Young in 1998. Photograph: Candice C Cusic/AP

In fact, RPM or .rpm , is a file format or extension referring to the package itself. It has since been adopted by many Linux distributions (distros) like CentOS, OpenSUSE, Oracle Linux, and AIX, just to name a few. Although, yum (for version 7 Linux distros), and now dnf (for version 8+  Linux distros), are more popular options for sysadmins, they are all package managers essentially–with differences in their functionality. However, this article will focus on popular rpm commands familiar to systems administrators, system engineers, and Linux enthusiasts around the world.

The Five RPM command modes

Installing RPM packages

Before we begin, let’s download some rpms to install. Click any of the links below to download rpm packages for your Linux distribution. For this demonstration, we will utilize a CentOS7 Linux virtual machine (VM).

  • redhat.com – Red Hat’s rpm mirror. You will need to sign up for an account and free trial to gain access to it.
  • centos.org – CentOS rpm mirror. Essentially similar rpms to Redhat as CentOS (until version 8) was developed to closely mirror Red Hat.
  • rpmfind.netrpmfind mirror located in the CREATIS Biomedical Imaging Research Lab in Lyon, France.
  • rpm.pbone.net –  rpm search tool for Linux users who install or compile new software and need to investigate possible missing libraries, files, or rpm packets on their systems.
  • freshrpms.net – Managed by Matthias Saou, a systems and network administrator, rpm package builder, and tester who lives in Spain. The website features several mirror lists for various versions of Redhat and Fedora–mostly FTP links.

Important Things to Consider

Ensure that you have sudo privileges to run rpm commands as root as any attempts to install or remove rpm packages will fail without it. In addition, we will demonstrate rpm installs using the following rpm packages (below):

  • mlocate-0.26-30.el9.x86_64.rpm
  • gedit-40.0-6.el9.x86_64.rpm
  • vsftpd-3.0.2-29.el7_9.x86_64.rpm
  • vsftpd-3.0.5-5.el9.x86_64.rpm

NOTE: We can also download individual rpms from the CentOS repository by using the yumdownloader command. Reference this yum article for further details.

RPM Install Example

This rpm command (below) is used to install mlocate, a Linux utility for finding files. It was executed using the (-ivh) option. The i stands for install and installs the package, v stands for verbose and is responsible for the pretty display. The h stands for print the hash (#) symbol. The hash symbol is printed as the package archive is being unpacked.

				
					[admin@localhost ~]$ sudo rpm -ivh mlocate-0.26-30.el9.x86_64.rpm 
Verifying...                          ################################# [100%]
Preparing...                          ################################# [100%]
Updating / installing...
   1:mlocate-0.26-30.el9              ################################# [100%]

				
			

RPM Install Example Without Dependencies

More often than not, rpm packages require dependencies and these dependent rpms contain files and libraries that applications rely on to run properly. This is where the yum command is more useful. It automatically accounts for and resolves dependencies. Also, depending on the situation and the package we want installed, we can force a rpm install using the --nodeps (or ignore dependencies) option (below).

				
					[admin@localhost ~]$ sudo rpm -ivh gedit-40.0-6.el9.x86_64.rpm --nodeps 
Verifying...                          ################################# [100%]
Preparing...                          ################################# [100%]
Updating / installing...
   1:gedit-40.0-6.el9                 ################################# [100%]

				
			

However, this is not considered best practice. Forcing a rpm install can cause an application to lose some functionality or fail to run entirely. The image below illustrates the rpm install of gedit, a small yet powerful text editor designed for the GNOME desktop.

				
					[admin@localhost ~]$ sudo rpm -ivh gedit-40.0-6.el9.x86_64.rpm 
error: Failed dependencies:
	desktop-file-utils >= 0.22-6 is needed by gedit-2:40.0-6.el9.x86_64
	gsettings-desktop-schemas is needed by gedit-2:40.0-6.el9.x86_64
	gspell(x86-64) >= 1.0 is needed by gedit-2:40.0-6.el9.x86_64
	gtk3(x86-64) >= 3.22 is needed by gedit-2:40.0-6.el9.x86_64
	gtksourceview4(x86-64) >= 4.0.2 is needed by gedit-2:40.0-6.el9.x86_64
	gvfs is needed by gedit-2:40.0-6.el9.x86_64
	libatk-1.0.so.0()(64bit) is needed by gedit-2:40.0-6.el9.x86_64
	libcairo.so.2()(64bit) is needed by gedit-2:40.0-6.el9.x86_64
	libgdk-3.so.0()(64bit) is needed by gedit-2:40.0-6.el9.x86_64
	libgdk_pixbuf-2.0.so.0()(64bit) is needed by gedit-2:40.0-6.el9.x86_64
	libgspell-1.so.2()(64bit) is needed by gedit-2:40.0-6.el9.x86_64
	libgtk-3.so.0()(64bit) is needed by gedit-2:40.0-6.el9.x86_64
	libgtksourceview-4.so.0()(64bit) is needed by gedit-2:40.0-6.el9.x86_64
	libpango-1.0.so.0()(64bit) is needed by gedit-2:40.0-6.el9.x86_64
	libpeas-1.0.so.0()(64bit) is needed by gedit-2:40.0-6.el9.x86_64
	libpeas-gtk-1.0.so.0()(64bit) is needed by gedit-2:40.0-6.el9.x86_64
	libpeas-loader-python3(x86-64) is needed by gedit-2:40.0-6.el9.x86_64
	python3-gobject >= 3.0.0 is needed by gedit-2:40.0-6.el9.x86_64
	zenity is needed by gedit-2:40.0-6.el9.x86_64

				
			

As you can see (above), when the gedit package is installed without the --nodeps option, a number of dependencies are required to install it. The list of failed dependencies does not fully represent what’s missing as some of those dependent rpms also have dependencies. We will review how to check a package for dependencies later on in this post.

Removing or Uninstalling RPM packages

Removing or uninstalling rpm packages are just as straightforward as installing them. The difference lies in the options passed to the rpm command.

RPM Uninstall Example

The rpm command (below) used to remove the vsftpd (very secure FTP Daemon) package is executed using the (-evh) option. The e stands for erase and removes the package, v stands for verbose, and h prints the hash symbol.

				
					[admin@localhost ~]$ sudo rpm -evh vsftpd 
Preparing...                          ################################# [100%]
Cleaning up / removing...
   1:vsftpd-3.0.5-5.el9               ################################# [100%]

				
			

RPM Uninstall Example Without Dependencies

The same procedure applies for removing rpm packages using the--nodeps option. It is possible but not advised. From a best practice standpoint, exercising this option can also negatively affect other running applications on our machine.

				
					[admin@localhost ~]$ sudo rpm -evh vsftpd --nodeps
Preparing...                          ################################# [100%]
Cleaning up / removing...
   1:vsftpd-3.0.5-5.el9               ################################# [100%]
				
			

Using the rpm command to remove or install rpms should only be exercised in rare one-off cases where the package requires no dependencies to install it. Or, if the package does not belong to any available repositories. In this instance however, the vsftpd package requires no dependencies to install it properly. Therefore, using the --nodeps option to remove it will have no impact on our machine.

Upgrading RPM packages

In order to upgrade rpm packages, a different option is passed to the rpm command. For demonstration purposes, we have downloaded and installed an older version of the vsftpd package.

RPM Upgrade Example

The rpm command used to upgrade the vsftpd package is executed using the (-Uvh) option. The U stands for upgrade and updates the package to the latest version while retaining the current version–in case there are any issues. We now know what the v and options represent.
VSftpd upgrade example

Photo by admingeek from Infotechys

Referring to the image above, an older version of the vsftpd package (vsftpd-3.0.2-28.el7.x86_64.rpm) was installed. Then, it was updated to its latest version (vsftpd-3.0.2-29.el7_9.x86_64.rpm) as of the date of this publication.

Verifying RPM packages

In order to verify an rpm package for potential errors and ensure that everything checks out, pass the -V (verify) option to the rpm command along with the package name.

RPM Verify Example

For this demonstration, we will verify the vsftpd package.

				
					[admin@localhost ~]$ sudo rpm -V vsftpd
				
			

You will not see any output from running this command if everything checks out with the installed package (above).  The rpm verify command only reports a problem if one exists, and displays the output to your terminal. It will report missing files and dependencies.

				
					[admin@localhost ~]$ sudo rpm -V vsftpd
missing   c /etc/vsftpd/vsftpd.conf
missing   d /usr/share/doc/vsftpd/COPYING
				
			

This is a sample output (above) of what we should expect to see if there’s a problem to report. The letter c in front of the file listing, indicates a configuration file is missing (vsftpd.conf). The d character represents missing documentation files.

				
					[root@localhost ~]# rpm -Va
S.5....T.  c /etc/dnf/dnf.conf
....L....  c /etc/pam.d/fingerprint-auth
....L....  c /etc/pam.d/password-auth
....L....  c /etc/pam.d/postlogin
....L....  c /etc/pam.d/smartcard-auth
....L....  c /etc/pam.d/system-auth
.......T.  c /etc/openldap/ldap.conf

				
			

To verify every package installed on a machine, pass the (-Va) option (a means all) to the rpm command (above). This process could take a few minutes depending on how many rpms are installed on a machine.

The table below displays the letter codes used to indicate a problem with the rpm and what they mean.

Letter Code

Meaning

c

Missing configuration file(s)

d

Missing documentation file(s)

S

File size is different

M

File mode is different

5

MD5 Checksum is different

D

Major and minor version numbers on a device file are different

L

Mismatch Link

U

File ownership is different

G

File group ownership is different

T

File time (mtime) is different

Querying RPM packages

RPM commands that querying packages for various types of information, are probably the most common of the commonly used RPM commands among Linux sysadmins and end-users across the globe. In this section, we will review some rpm query commands to gain a better understanding of its capabilities.

RPM Query Example: List all installed packages

The rpm command used to list all the packages installed on a machine is executed using the (-qa) option (below). The q stands for query and lists all installed packages, a stands for all.
				
					[admin@localhost ~]$ sudo rpm -qa
libgcc-11.4.1-2.3.el9.x86_64
crypto-policies-20231113-1.gite9247c2.el9.noarch
tzdata-2023c-1.el9.noarch
gawk-all-langpacks-5.1.0-6.el9.x86_64
python3-setuptools-wheel-53.0.0-12.el9.noarch
publicsuffix-list-dafsa-20210518-3.el9.noarch
pcre2-syntax-10.40-4.el9.noarch
ncurses-base-6.2-10.20210508.el9.noarch
linux-firmware-whence-20231030-141.el9.noarch
linux-firmware-20231030-141.el9.noarch
libssh-config-0.10.4-11.el9.noarch
libreport-filesystem-2.15.2-6.el9.noarch
dnf-data-4.14.0-9.el9.noarch
kbd-misc-2.4.0-9.el9.noarch
kbd-legacy-2.4.0-9.el9.noarch
hwdata-0.348-9.11.el9.noarch
fonts-filesystem-2.0.5-7.el9.1.noarch
dejavu-sans-fonts-2.37-18.el9.noarch
langpacks-core-font-en-3.0-16.el9.noarch
firewalld-filesystem-1.2.5-1.el9.noarch
coreutils-common-8.32-34.el9.x86_64

				
			
To display the total number of installed packages on a Linux machine, execute the same rpm query command and pipe it to the word count (wc -l) list option. Currently, there 675 rpms installed on our CentOS7 machine (illustrated below).
				
					[admin@localhost ~]$ sudo rpm -qa | wc -l
675

				
			

RPM Query Example: List all files belonging to an installed RPM package

To list all of the files provided by an installed rpm package, pass the (-ql) (query list) option to the rpm command (below).
				
					[admin@localhost ~]$ sudo rpm -ql mlocate
/etc/updatedb.conf
/usr/bin/locate
/usr/bin/updatedb
/usr/lib/.build-id
/usr/lib/.build-id/1c
/usr/lib/.build-id/1c/e0df0507d0a878ad36e20f6879590b1136fdb0
/usr/lib/.build-id/45
/usr/lib/.build-id/45/f571493b6b362c198cb71edd1a0e1a7e383545
/usr/lib/systemd/system/mlocate-updatedb.service
/usr/lib/systemd/system/mlocate-updatedb.timer
/usr/libexec/mlocate-run-updatedb
/usr/share/doc/mlocate
/usr/share/doc/mlocate/AUTHORS

				
			

RPM Query Example: Check which rpm is associated with a file

If you are presented with the path to a file or a directory (e.g. /var/ftp/pub) and asked to determine what rpm package provides said file or directory–you can pass the (-qf) (query file) option to the rpm command to do so. We can determine that the (vsftpd-3.0.5-5.el9.x86_64) package provides /var/ftp/pub (illustrated below).
				
					[admin@localhost ~]$ sudo rpm -qf /var/ftp/pub
vsftpd-3.0.5-5.el9.x86_64
				
			

RPM Query Example: List recently installed rpms

Passing the --last option to the rpm -qa (rpm query all installed packages) command, displays recently installed rpm packages to your terminal.
				
					[admin@localhost ~]$ rpm -qa --last
vsftpd-3.0.5-5.el9.x86_64                     Sat 20 Jan 2024 12:17:54 AM UTC
mlocate-0.26-30.el9.x86_64                    Fri 19 Jan 2024 11:55:52 PM UTC
haveged-1.9.18-1.el9.x86_64                   Mon 01 Jan 2024 11:06:48 AM UTC
tuned-2.21.0-1.el9.noarch                     Mon 01 Jan 2024 11:06:37 AM UTC
python3-perf-5.14.0-391.el9.x86_64            Mon 01 Jan 2024 11:06:37 AM UTC
libtraceevent-1.5.3-3.el9.x86_64              Mon 01 Jan 2024 11:06:37 AM UTC
hdparm-9.62-2.el9.x86_64                      Mon 01 Jan 2024 11:06:37 AM UTC
virt-what-1.25-5.el9.x86_64                   Mon 01 Jan 2024 11:06:36 AM UTC
python3-pyudev-0.22.0-6.el9.noarch            Mon 01 Jan 2024 11:06:36 AM UTC
python3-linux-procfs-0.7.3-1.el9.noarch       Mon 01 Jan 2024 11:06:36 AM UTC
polkit-pkla-compat-0.1-21.el9.x86_64          Mon 01 Jan 2024 11:06:36 AM UTC
polkit-libs-0.117-11.el9.x86_64               Mon 01 Jan 2024 11:06:36 AM UTC
polkit-0.117-11.el9.x86_64                    Mon 01 Jan 2024 11:06:36 AM UTC

				
			

Conclusion

We’ve reviewed the most commonly used rpm commands by Linux professionals and enthusiasts. However, we’re not scratching the surface of what’s possible. What do you think of our list? Are there rpm commands options you believe should belong on this list? If so, let us know in the comments section.

Related Posts

Leave a Reply

Your email address will not be published. Required fields are marked *