How to Use the RPM Command (with Examples)
RPM stands for "Redhat Package Manager" is a command-line package management tool for RHEL/CentOS based operating system. You can install, uninstall, update, query and verify package using the RPM command. This tool only works with packages built in .rpm format. RPM command can only install the specified package, it can not install the dependencies required for that package.
In this tutorial, we will show you how to use RPM package manager with some examples. If you are seeking for a guide on the new RedHat package manager DNF, have a look here: CentOS 8 Package Management with DNF on the Command Line
Prerequisites
- A server running CentOS, RHEL or Fedora.
- A root password is configured on your server.
Basic Syntax
The basic syntax of RPM command is shown below:
rpm [OPTION] [PACKAGENAME]
You can list all available options with RPM command using the following command:
rpm --help
You should see the following screen:
Installing, Updating and Removing Package with RPM
Before installing any RPM package, you can list the dependencies for that package with the following command:
rpm -qpR epel-release-latest-8.noarch.rpm
Output:
warning: epel-release-latest-8.noarch.rpm: Header V3 RSA/SHA256 Signature, key ID 2f86d6a1: NOKEY config(epel-release) = 8-7.el8 redhat-release >= 8 rpmlib(CompressedFileNames) <= 3.0.4-1 rpmlib(FileDigests) <= 4.6.0-1 rpmlib(PayloadFilesHavePrefix) <= 4.0-1 rpmlib(PayloadIsXz) <= 5.2-1
You can also get the information of that package with the following command:
rpm -qip epel-release-latest-8.noarch.rpm
Output:
warning: epel-release-latest-8.noarch.rpm: Header V3 RSA/SHA256 Signature, key ID 2f86d6a1: NOKEY Name : epel-release Version : 8 Release : 7.el8 Architecture: noarch Install Date: (not installed) Group : System Environment/Base Size : 30269 License : GPLv2 Signature : RSA/SHA256, Thursday 10 October 2019 12:19:30 PM EDT, Key ID 21ea45ab2f86d6a1 Source RPM : epel-release-8-7.el8.src.rpm Build Date : Thursday 10 October 2019 12:16:18 PM EDT Build Host : buildvm-04.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.
You can install this package using the following command:
rpm -ivh epel-release-latest-8.noarch.rpm
Output:
warning: epel-release-latest-8.noarch.rpm: Header V3 RSA/SHA256 Signature, key ID 2f86d6a1: NOKEY Verifying... ################################# [100%] Preparing... ################################# [100%] Updating / installing... 1:epel-release-8-7.el8 ################################# [100%]
You can install any RPM package without any dependencies using the following command:
rpm -ivh --nodeps epel-release-latest-8.noarch.rpm
To update the installed RPM package, run the following command:
rpm -Uvh epel-release-latest-8.noarch.rpm
Output:
warning: epel-release-latest-8.noarch.rpm: Header V3 RSA/SHA256 Signature, key ID 2f86d6a1: NOKEY Verifying... ################################# [100%] Preparing... ################################# [100%] package epel-release-8-7.el8.noarch is already installed
To remove the installed RPM package, run the following command:
rpm -ev epel-release
Output:
Preparing packages... epel-release-8-7.el8.noarch
Display Package Information with RPM
To display the detail information of any package run the following command:
rpm -ql epel-release
Output:
/etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-8 /etc/yum.repos.d/epel-playground.repo /etc/yum.repos.d/epel-testing.repo /etc/yum.repos.d/epel.repo /usr/lib/systemd/system-preset/90-epel.preset /usr/share/doc/epel-release /usr/share/doc/epel-release/GPL /usr/share/doc/epel-release/README-epel-8-packaging.md
You can find the configuration files of any package with the following command:
rpm -qc httpd
Output:
/etc/httpd/conf.d/autoindex.conf /etc/httpd/conf.d/userdir.conf /etc/httpd/conf.d/welcome.conf /etc/httpd/conf.modules.d/00-base.conf /etc/httpd/conf.modules.d/00-dav.conf /etc/httpd/conf.modules.d/00-lua.conf /etc/httpd/conf.modules.d/00-mpm.conf /etc/httpd/conf.modules.d/00-optional.conf /etc/httpd/conf.modules.d/00-proxy.conf /etc/httpd/conf.modules.d/00-systemd.conf /etc/httpd/conf.modules.d/01-cgi.conf /etc/httpd/conf/httpd.conf /etc/httpd/conf/magic /etc/logrotate.d/httpd /etc/sysconfig/htcacheclean
You can display more information about any package with the following command:
rpm -qi httpd
Output:
Name : httpd Version : 2.4.37 Release : 16.module_el8.1.0+256+ae790463 Architecture: x86_64 Install Date: Thursday 23 January 2020 11:48:36 PM EST Group : System Environment/Daemons Size : 5611291 License : ASL 2.0 Signature : RSA/SHA256, Monday 23 December 2019 05:22:02 PM EST, Key ID 05b555b38483c65d Source RPM : httpd-2.4.37-16.module_el8.1.0+256+ae790463.src.rpm Build Date : Monday 23 December 2019 03:46:30 PM EST Build Host : x86-02.mbox.centos.org Relocations : (not relocatable) Packager : CentOS Buildsys <[email protected]> Vendor : CentOS URL : https://httpd.apache.org/ Summary : Apache HTTP Server Description : The Apache HTTP Server is a powerful, efficient, and extensible web server.
To find the package from the directory or file with the following command:
rpm -qf /etc/NetworkManager/
Output:
NetworkManager-1.14.0-14.el8.x86_64 dhcp-client-4.3.6-30.el8.x86_64
Verify Package with RPM
To verify any package before installing it using the following command:
rpm -Vp epel-release-latest-8.noarch.rpm
Output:
warning: epel-release-latest-8.noarch.rpm: Header V3 RSA/SHA256 Signature, key ID 2f86d6a1: NOKEY
To verify all the installed rpm packages, run the following command:
rpm -Va
Output:
.......T. c /etc/kdump.conf .M....... g /var/lib/plymouth/boot-duration .M....... g /var/cache/dnf/packages.db .....UG.. g /var/lib/sss/mc/group .....UG.. g /var/lib/sss/mc/initgroups .....UG.. g /var/lib/sss/mc/passwd .M....... c /etc/rc.d/rc.local .M....... c /etc/machine-id
Check Information about Installed Package with RPM
To verify any package whether it is installed or not with the following command:
To verify the installed package, run the following command:
rpm -q epel-release
If the specified package is installed, you should see the following output:
epel-release-8-7.el8.noarch
To verify the package that is not installed, run the following command:
rpm -q mysql-server
You should get the following output:
package mysql-server is not installed
To list all the packages that are installed in your system, run the following command:
rpm -qa
Output:
dos2unix-7.4.0-3.el8.x86_64 platform-python-pip-9.0.3-13.el8.noarch geolite2-country-20180605-1.el8.noarch symlinks-1.4-19.el8.x86_64 python3-six-1.11.0-8.el8.noarch fontpackages-filesystem-1.44-22.el8.noarch rootfiles-8.1-22.el8.noarch polkit-0.115-6.el8.x86_64 xkeyboard-config-2.24-3.el8.noarch iwl6050-firmware-41.28.5.1-92.el8.1.noarch libmodulemd1-1.8.0-5.el8.x86_64 pkgconf-m4-1.4.2-1.el8.noarch iwl5000-firmware-8.83.5.1_1-92.el8.1.noarch samba-common-4.9.1-8.el8.noarch kbd-misc-2.0.4-8.el8.noarch
To list all installed package by name and size, run the following command:
rpm -qa --queryformat '%{name} %{size}\n'
Output:
dos2unix 682042 platform-python-pip 7746190 geolite2-country 3424334 symlinks 19682 python3-six 100282 fontpackages-filesystem 0 rootfiles 599
Find Manual Page of Any Package with RPM
You can run the following to know the list of documentation for a package that owns a file or folder.
rpm -qdf /etc/NetworkManager/
Output:
/usr/share/doc/NetworkManager/AUTHORS /usr/share/doc/NetworkManager/CONTRIBUTING /usr/share/doc/NetworkManager/NEWS /usr/share/doc/NetworkManager/README /usr/share/doc/NetworkManager/TODO /usr/share/doc/NetworkManager/examples/server.conf /usr/share/man/man1/nm-online.1.gz /usr/share/man/man1/nmcli.1.gz /usr/share/man/man5/NetworkManager.conf.5.gz /usr/share/man/man5/nm-settings-ifcfg-rh.5.gz /usr/share/man/man5/nm-settings-keyfile.5.gz /usr/share/man/man5/nm-settings.5.gz /usr/share/man/man5/nm-system-settings.conf.5.gz /usr/share/man/man7/nmcli-examples.7.gz /usr/share/man/man8/NetworkManager.8.gz /usr/share/doc/dhcp-client/README.dhclient.d /usr/share/doc/dhcp-client/dhclient-enter-hooks /usr/share/doc/dhcp-client/dhclient.conf.example /usr/share/doc/dhcp-client/dhclient6.conf.example /usr/share/man/man5/dhclient.conf.5.gz /usr/share/man/man5/dhclient.leases.5.gz /usr/share/man/man8/dhclient-script.8.gz /usr/share/man/man8/dhclient.8.gz
Conclusion
In the above tutorial, we learned how to manage packages with RPM on CentOS 8 operating system. I hope this will help you to perform day-to-day tasks.