How to use RPM commands (with examples)
How to use RPM commands (with examples)
RPM stands for “Redhat Package Manager”, which is a command line package management tool for RHEL / CentOS-based operating systems. You can use RPM commands to install, uninstall, update, query and verify packages. This tool is only available for packages built in .rpm format. The RPM command can only install the specified software package, not the dependencies required by the software package.
In this tutorial, we will show you how to use the RPM package manager with some examples. If you are looking for a guide on the new RedHat package manager DNF, check 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 grammar
The basic syntax of the RPM command is as follows:
rpm [OPTION] [PACKAGENAME]
You can use the following command to list all available options using the RPM command:
rpm --help
You should see the following screen:
Install, update and remove packages using RPM
Before installing any RPM package, you can use the following command to list the dependencies of that package:
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 information about the package using 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 use the following command to install any RPM-free packages:
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 packages, run the following command:
rpm -ev epel-release
Output:
Preparing packages... epel-release-8-7.el8.noarch
Display packaging information using RPM
To display the details 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 file for any package using 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 use the following command to display more information about any package:
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.
Use the following command to find packages from a directory or file:
rpm -qf /etc/NetworkManager/
Output:
NetworkManager-1.14.0-14.el8.x86_64 dhcp-client-4.3.6-30.el8.x86_64
Validate software package using RPM
Use the following command to verify any packages before installing them:
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 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
Use RPM to check information about installed packages
Use the following command to verify that no packages are installed:
To verify the installed packages, run the following command:
rpm -q epel-release
If the specified package is already installed, you should see the following output:
epel-release-8-7.el8.noarch
To verify that the packages are 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 packages installed on 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 packages 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 man pages for any package using RPM
You can run the following command to see the document list of the package that owns the 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
in conclusion
In the above tutorial, we learned how to use the RPM management package on the CentOS 8 operating system. I hope this will help you perform your daily tasks.