Table of Contents
In this tutorial, I will take you through 25 Practical and Useful RPM Command Examples in Linux. An RPM is a special archive file that contains software packaged for installation on RHEL/CentOS based servers. Any software package required to be installed in RHEL/CentOS based server has to be an rpm package. To install an rpm package you need to use an open source tool called rpm freely available on RHEL/CentOS/Fedora Servers.
What is RPM DB
It is a database which maintains the information of all the installed packages in a RHEL/CentOS Linux Servers. It also contains information about the package upgradation and list of updates applied on the Server.
SYNOPSIS
QUERYING AND VERIFYING PACKAGES:
rpm {-q|–query} [select-options] [query-options]
rpm {-V|–verify} [select-options] [verify-options]
INSTALLING, UPGRADING, AND REMOVING PACKAGES:
rpm {-i|–install} [install-options] PACKAGE_FILE …
rpm {-U|–upgrade} [install-options] PACKAGE_FILE …
rpm {-F|–freshen} [install-options] PACKAGE_FILE …
rpm {-e|–erase} [–allmatches] [–justdb] [–nodeps] [–noscripts]
[–notriggers] [–test] PACKAGE_NAME …
MISCELLANEOUS:
rpm {–querytags|–showrc}
rpm {–setperms|–setugids} PACKAGE_NAME …
Practical and Useful RPM Command Examples in Linux
Also Read: How to Convert/Change Time to Epoch Time using date utility on Linux or Unix Server
Example 1: How to Check RPM Command Version
You need to use rpm --version
command to check the current rpm version. As you can see from below output, current version is 4.11.3.
[root@localhost ~]# rpm --version RPM version 4.11.3
--version
: print the version of rpm being used. More on rpm Man Page.
NOTE:
root
user to run all the below commands.You can use any user with sudo
access to run all these commands. For more information Please check Step by Step: How to Add User to Sudoers to provide sudo
access to the User.Example 2: How to Install a Package Using RPM Command
If you want to install any rpm package from some direct URL then you need to use rpm -i <package_url>
command. Here we are installing EPEL Repository package directly from the URL.
[root@localhost ~]# rpm -i https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
-i
: install package(s). More on rpm Man Page.
Example 3: How to Use verbose(-v) Option with RPM Command
If you want to see the operations of running rpm command then it is always a good idea to run all rpm commands with verbose(-v)
option enabled.
[root@localhost ~]# rpm -iv https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm Retrieving https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm Preparing packages... epel-release-7-12.noarch
-v
: provide more detailed output. More on rpm Man Page.
Example 4: How to Use hash(-h) option with RPM Command
If you want to print the hash marks during installation then you need to use -h
option with rpm command. Hash mark will act as a progress bar that gives information about the percentage of installation completion.
[root@localhost ~]# rpm -ivh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm Retrieving https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm Preparing... ################################# [100%] Updating / installing... 1:epel-release-7-12 ################################# [100%]
-h
: print hash marks as package installs. More on rpm Man Page.
Example 5: How to Check all the Packages installed in RPM DB
If you want to query all the installed packages from RPM DB then you need to use rpm -qa
command as shown below.
[root@localhost ~]# rpm -qa glusterfs-cli-6.0-29.el7.x86_64 langtable-data-0.0.31-4.el7.noarch teamd-1.29-1.el7.x86_64 perl-Types-Serialiser-1.0-1.el7.noarch ncurses-base-5.9-14.20130511.el7_4.noarch perl-podlators-2.5.1-3.el7.noarch ndctl-libs-65-5.el7.x86_64 kpartx-0.4.9-131.el7.x86_64 net-snmp-libs-5.7.2-48.el7_8.1.x86_64 basesystem-10.0-7.el7.centos.noarch perl-Time-HiRes-1.9725-3.el7.x86_64 plymouth-graphics-libs-0.8.9-0.33.20140113.el7.centos.x86_64 perl-YAML-0.84-5.el7.noarch info-5.1-5.el7.x86_64 perl-Time-Local-1.2300-2.el7.noarch createrepo-0.9.9-28.el7.noarch policycoreutils-2.5-34.el7.x86_64 lshw-B.02.18-14.el7.x86_64 pcre-8.32-17.el7.x86_64 perl-5.16.3-295.el7.x86_64 xorg-x11-server-common-1.20.4-10.el7.x86_64 plymouth-core-libs-0.8.9-0.33.20140113.el7.centos.x86_64 python-jinja2-2.7.2-4.el7.noarch libtasn1-4.10-1.el7.x86_64 python-backports-ssl_match_hostname-3.5.0.1-1.el7.noarch
-q
: query format. More on rpm Man Page.
-a
: query/verify all packages. More on rpm Man Page.
Example 6: How to Query Specific Package from RPM DB
If you want to query a specific package from RPM DB then you need to grep
that package name from rpm -qa
output. In this example we are trying to query EPEL Repository package name from RPM DB using rpm -qa | grep -i epel-release
command as shown below.
[root@localhost ~]# rpm -qa | grep -i epel-release epel-release-7-12.noarch
Example 7: How to Remove a Package without removing any of its dependencies
If you want to remove any package without removing any of its dependencies then you need to use --nodeps
option with rpm command as shown below. In this example, we are trying to remove EPEL Repository package using rpm -evh --nodeps epel-release
command as shown below.
[root@localhost ~]# rpm -evh --nodeps epel-release Preparing... ################################# [100%] Cleaning up / removing... 1:epel-release-7-12 ################################# [100%]
-e
: erase (uninstall) package. More on rpm Man Page.
Example 8: How to Query Documentation of an Installed Command
If you want to query documentation of an installed command then you need to use -qdf
option with rpm command as shown below. In this example, we are querying the documentation of ls
command using rpm -qdf /usr/bin/ls
command as shown below.
[root@localhost ~]# rpm -qdf /usr/bin/ls /usr/share/doc/coreutils-8.22/ABOUT-NLS /usr/share/doc/coreutils-8.22/COPYING /usr/share/doc/coreutils-8.22/ChangeLog.bz2 /usr/share/doc/coreutils-8.22/NEWS /usr/share/doc/coreutils-8.22/README /usr/share/doc/coreutils-8.22/THANKS /usr/share/doc/coreutils-8.22/TODO /usr/share/doc/coreutils-8.22/fileutils/ChangeLog-1997.bz2 /usr/share/doc/coreutils-8.22/fileutils/ChangeLog.bz2 /usr/share/doc/coreutils-8.22/fileutils/NEWS /usr/share/doc/coreutils-8.22/sh-utils/ChangeLog.0.bz2 /usr/share/doc/coreutils-8.22/sh-utils/ChangeLog.bz2
-d
: list all documentation files. More on rpm Man Page.
-f
: query/verify package(s) owning file. More on rpm Man Page.
Example 9: How to Query Documentation of an Installed Package
If you want to query documentation of an installed package then you need to use -qd
option with rpm command. In this example, we are querying the documentation of EPEL Repository package using rpm -qd epel-release
command as shown below.
[root@localhost ~]# rpm -qd epel-release /usr/share/doc/epel-release-7/GPL
Example 10: How to Verify All the Installed RPM Packages
If you want to verify all the installed rpm packages then you need to use rpm -Va
command as shown below.
[root@localhost ~]# rpm -Va .......T. c /etc/profile S.5....T. c /var/lib/unbound/root.key .M....... g /etc/lvm/cache/.cache S.5....T. c /root/.bash_profile S.5....T. c /root/.bashrc S.5....T. /usr/bin/pip S.5....T. /usr/bin/pip2 S.5....T. /usr/bin/pip2.7 missing /usr/lib/python2.7/site-packages/pip-8.1.2-py2.7.egg-info missing /usr/lib/python2.7/site-packages/pip-8.1.2-py2.7.egg-info/PKG-INFO missing /usr/lib/python2.7/site-packages/pip-8.1.2-py2.7.egg-info/SOURCES.txt missing /usr/lib/python2.7/site-packages/pip-8.1.2-py2.7.egg-info/dependency_links.txt
-V
: verify. More on rpm Man Page.
Example 11: How to Check all Imported GPG Key
To check all the imported GPG Key you need to use rpm -qa gpg-pubkey*
command as specified below.
[root@localhost ~]# rpm -qa gpg-pubkey* gpg-pubkey-f4a80eb5-53a7ff4b gpg-pubkey-f5cf6c1e-5544f037 gpg-pubkey-352c64e5-52ae6884 gpg-pubkey-5072e1f5-4e773e2a
Example 12: How to Upgrade a Package in Linux
You can also upgrade a package in Linux using rpm command. In this example, we are trying to upgrade EPEL Repository package using rpm -Uvh epel-release-latest-7.noarch.rpm
command as shown below.
[root@localhost ~]# rpm -Uvh epel-release-latest-7.noarch.rpm Preparing... ################################# [100%] Updating / installing... 1:epel-release-7-12 ################################# [100%]
-U
: upgrade package(s). More on rpm Man Page.
Example 13: How to Install Package without its dependencies in Linux
If you have downloaded any package in your local system and you want to install that package locally without its dependencies then you have to use below rpm
command. In this example, we are trying to install local downloaded EPEL Repository package using rpm -ivh --nodeps epel-release-latest-7.noarch.rpm
command as shown below.
[root@localhost ~]# rpm -ivh --nodeps epel-release-latest-7.noarch.rpm Preparing... ################################# [100%] Updating / installing... 1:epel-release-7-12 ################################# [100%]
--nodeps
: do not verify package dependencies
Example 14: How to Remove RPM Package from Linux Server
To remove RPM Package from Linux server you can use -evh
option with rpm command. In this example, we are trying to remove EPEL Repository package using rpm -evh epel-release
command as shown below.
[root@localhost ~]# rpm -evh epel-release Preparing... ################################# [100%] Cleaning up / removing... 1:epel-release-7-12 ################################# [100%]
Example 15: How to Check all the Recently Installed Packages
If you are looking for all the recently installed packages then you can make use of --last
option available with rpm command. In this example we are checking all the recently installed packages using rpm -qa --last
command as shown below.
[root@localhost ~]# rpm -qa --last epel-release-7-12.noarch Wed 11 Nov 2020 11:23:52 AM EST oniguruma-6.8.2-1.el7.x86_64 Tue 10 Nov 2020 10:46:12 PM EST logrotate-3.8.6-19.el7.x86_64 Sat 07 Nov 2020 08:21:43 AM EST arpwatch-2.1a15-36.el7.x86_64 Sat 07 Nov 2020 06:02:37 AM EST python36-websocket-client-0.47.0-2.el7.noarch Sun 01 Nov 2020 05:27:19 PM EST python36-urllib3-1.25.6-2.el7.noarch Sun 01 Nov 2020 05:27:19 PM EST python36-six-1.14.0-2.el7.noarch Sun 01 Nov 2020 05:27:19 PM EST python36-requests-2.14.2-2.el7.noarch Sun 01 Nov 2020 05:27:19 PM EST python36-pysocks-1.6.8-7.el7.noarch Sun 01 Nov 2020 05:27:19 PM EST python36-idna-2.7-2.el7.noarch Sun 01 Nov 2020 05:27:19 PM EST
--last
: list package(s) by install time, most recent first
Example 16: How to Check the Dependencies of a Package before Installation
If you want to check all the dependencies of a package then you need to use -qpR
option with rpm command. In this example we are trying to check all the dependencies of EPEL Repository package using rpm -qpR epel-release-latest-7.noarch.rpm
command as shown below.
[root@localhost ~]# rpm -qpR epel-release-latest-7.noarch.rpm config(epel-release) = 7-12 redhat-release >= 7 rpmlib(CompressedFileNames) <= 3.0.4-1 rpmlib(FileDigests) <= 4.6.0-1 rpmlib(PayloadFilesHavePrefix) <= 4.0-1 rpmlib(PayloadIsXz) <= 5.2-1
-p
: query/verify a package file.
-R
: List capabilities on which this package depends.
Example 17: How to Check the Installation Path of a Linux Package
If you want to check the installation path of a Linux package then you need to use -ql
option with rpm command. In this example, we are looking for the installation path of Core Utils
package using rpm -ql coreutils-8.22-24.el7.x86_64
command as shown below.
[root@localhost ~]# rpm -ql coreutils-8.22-24.el7.x86_64 /etc/DIR_COLORS /etc/DIR_COLORS.256color /etc/DIR_COLORS.lightbgcolor /etc/profile.d/colorls.csh /etc/profile.d/colorls.sh /usr/bin/[ /usr/bin/arch /usr/bin/base64 /usr/bin/basename /usr/bin/cat /usr/bin/chcon /usr/bin/chgrp /usr/bin/chmod /usr/bin/chown /usr/bin/cksum /usr/bin/comm
-l
: List files in package.
Example 18: How to Check the Package name of a Linux Command
You can also check the package name of any of the Linux command using -qf
option with rpm command. This only requires to find out the complete path of the command by using which <command>
. Once you know the path you can directly use rpm -qf <linux_command_path>
. In this example we are trying to check the package name of ls
command using rpm -qf /usr/bin/ls
command as shown below.
[root@localhost ~]# rpm -qf /usr/bin/ls coreutils-8.22-24.el7.x86_64
Example 19: How to Check the Signature of RPM Package
You also have an option available with rpm command to check the signature of a rpm package. This can be checked by using --checksig
option. In this example, we are checking the signature of EPEL Repository package using rpm --checksig epel-release-latest-7.noarch.rpm
command as shown below.
[root@localhost ~]# rpm --checksig epel-release-latest-7.noarch.rpm epel-release-latest-7.noarch.rpm: rsa sha1 (md5) pgp md5 OK
Example 20: How to Verify a Specific RPM Package
If you want to verify any of the rpm package then you need to use -Vp
option with rpm command. In this example, we are trying to verify the EPEL Repository package using rpm -Vp epel-release-latest-7.noarch.rpm
command as shown below.
[root@localhost ~]# rpm -Vp epel-release-latest-7.noarch.rpm missing /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7 missing c /etc/yum.repos.d/epel-testing.repo missing c /etc/yum.repos.d/epel.repo missing /usr/lib/systemd/system-preset/90-epel.preset missing /usr/share/doc/epel-release-7 missing d /usr/share/doc/epel-release-7/GPL
Example 21: How to Query a Package before Installation
If you want to query a package before installation then you need to use -qip
option with rpm command as shown below. In this example, we are trying to check the EPEL Repository package using rpm -qip epel-release-latest-7.noarch.rpm
command as shown below.
[root@localhost ~]# rpm -qip epel-release-latest-7.noarch.rpm Name : epel-release Version : 7 Release : 12 Architecture: noarch Install Date: (not installed) Group : System Environment/Base Size : 25032 License : GPLv2 Signature : RSA/SHA256, Wed 18 Sep 2019 08:56:09 AM EDT, Key ID 6a2faea2352c64e5 Source RPM : epel-release-7-12.src.rpm Build Date : Tue 17 Sep 2019 07:26:40 PM EDT Build Host : buildvm-23.phx2.fedoraproject.org Relocations : (not relocatable) Packager : Fedora Project Vendor : Fedora Project URL : http://download.fedoraproject.org/pub/epel Bug URL : https://bugz.fedoraproject.org/epel-release Summary : Extra Packages for Enterprise Linux repository configuration Description : This package contains the Extra Packages for Enterprise Linux (EPEL) repository GPG key as well as configuration for yum.
Example 22: How to Query the List of Configuration Files for a Package
If you want to check the list of configuration files for a package then you need to use -qc
option with rpm command as shown below. In this example, we are trying to get the list of configuration files for EPEL Repository package using rpm -qc epel-release
command as shown below.
[root@localhost ~]# rpm -qc epel-release /etc/yum.repos.d/epel-testing.repo /etc/yum.repos.d/epel.repo
Example 23: How to Query the List of Configuration Files for a Command
If you want to query the list of configuration files for a command instead of a package then you need to use -qcf
option with rpm command. In this example we are getting the list of configuration files for ls command using rpm -qcf /usr/bin/ls
command as shown below.
[root@localhost ~]# rpm -qcf /usr/bin/ls /etc/DIR_COLORS /etc/DIR_COLORS.256color /etc/DIR_COLORS.lightbgcolor /etc/profile.d/colorls.csh /etc/profile.d/colorls.sh
Example 24: How to Check all the Options available with RPM Command
If you want to check all the options available with rpm command then you need to use rpm --help
command to check that as you can see below.
[root@localhost ~]# rpm --help Usage: rpm [OPTION...] Query/Verify package selection options: -a, --all query/verify all packages -f, --file query/verify package(s) owning file -g, --group query/verify package(s) in group -p, --package query/verify a package file --pkgid query/verify package(s) with package identifier --hdrid query/verify package(s) with header identifier --triggeredby query the package(s) triggered by the package --whatrequires query/verify the package(s) which require a dependency --whatprovides query/verify the package(s) which provide a dependency --nomanifest do not process non-package files as manifests
Example 25: How to Check the Man Page of rpm command
You can check the Man page of rpm command using man rpm
command as shown below.
[root@localhost ~]# man rpm RPM(8) System Manager's Manual RPM(8) NAME rpm - RPM Package Manager SYNOPSIS QUERYING AND VERIFYING PACKAGES: rpm {-q|--query} [select-options] [query-options] rpm {-V|--verify} [select-options] [verify-options] INSTALLING, UPGRADING, AND REMOVING PACKAGES: rpm {-i|--install} [install-options] PACKAGE_FILE ... rpm {-U|--upgrade} [install-options] PACKAGE_FILE ... rpm {-F|--freshen} [install-options] PACKAGE_FILE ... rpm {-e|--erase} [--allmatches] [--justdb] [--nodeps] [--noscripts] [--notriggers] [--test] PACKAGE_NAME ... MISCELLANEOUS: rpm {--querytags|--showrc} rpm {--setperms|--setugids} PACKAGE_NAME ...
Popular Recommendations:-
How to Install jq(JSON Processor) on RHEL/CentOS 7/8
How to Defragment an XFS Filesystem in Linux(5 Simple and Effective Steps)
How to Install Arpwatch tool on RHEL/CentOS 7/8(Simple and Effective Steps)
How to Install and Configure Squid Proxy Server on RHEL/CentOS 7/8
Python3: ModuleNotFoundError: No Module Named “prettytable” in Linux
How to List all the Installed Python Modules in Linux{2 Easy Methods}
Solved: ModuleNotFoundError: No Module Named “requests” in Python 3
How to Install and Enable EPEL Repository on RHEL/CentOS 7/8{Simple and Easy Steps}