RPM, which stands for “Redhat Package Manager,” is a command-line package management tool primarily used for RHEL/CentOS-based operating systems. With the RPM command, you can efficiently install, uninstall, update, query, and verify packages that are specifically in the .rpm format. However, RPM focuses solely on the package specified, meaning it does not handle dependencies that the package may require.
This guide will walk you through using the RPM package manager, complete with examples. For guidance on using the newer RedHat package manager, DNF, refer to the following article: CentOS 8 Package Management with DNF on the Command Line.
Prerequisites
- A server running CentOS, RHEL, or Fedora.
- Root access configured with a password on your server.
Basic Syntax
The basic syntax of the RPM command is:
rpm [OPTION] [PACKAGENAME]
To list all available options with the RPM command, use:
rpm --help
Expected output:
Installing, Updating, and Removing Packages with RPM
Before installing an RPM package, list its dependencies with:
rpm -qpR epel-release-latest-8.noarch.rpm
Output sample:
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
To gather more information about a package, use:
rpm -qip epel-release-latest-8.noarch.rpm
Output sample:
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.
To install the package, use:
rpm -ivh epel-release-latest-8.noarch.rpm
Sample 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%]
To bypass dependency checks during installation, use:
rpm -ivh --nodeps epel-release-latest-8.noarch.rpm
For updating an installed RPM package, execute:
rpm -Uvh epel-release-latest-8.noarch.rpm
Output sample:
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 an installed RPM package, use:
rpm -ev epel-release
Sample output:
Preparing packages... epel-release-8-7.el8.noarch
Display Package Information with RPM
To view detailed information about a package, execute:
rpm -ql epel-release
Output sample:
/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
To locate configuration files for a package, run:
rpm -qc httpd
Output sample:
/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
For additional package information, use:
rpm -qi httpd
Output example:
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 <bugs@centos.org> 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 associated with a directory or file, use:
rpm -qf /etc/NetworkManager/
Output sample:
NetworkManager-1.14.0-14.el8.x86_64 dhcp-client-4.3.6-30.el8.x86_64
Verify Package with RPM
To verify a package before installing, execute:
rpm -Vp epel-release-latest-8.noarch.rpm
Output example:
warning: epel-release-latest-8.noarch.rpm: Header V3 RSA/SHA256 Signature, key ID 2f86d6a1: NOKEY
To verify all installed packages, run:
rpm -Va
Output sample:
.......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 Packages with RPM
To verify if a package is installed, use:
rpm -q epel-release
If installed, you will see:
epel-release-8-7.el8.noarch
If a package is not installed, for instance, use:
rpm -q mysql-server
Expected output:
package mysql-server is not installed
To list all installed packages, execute:
rpm -qa
Output sample:
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 packages by name and size, run:
rpm -qa --queryformat '%{name} %{size}\n'
Output example:
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
To find a list of documentation for a package that owns a specific file or folder, use:
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 this tutorial, we’ve covered how to effectively manage packages using RPM on a CentOS 8 operating system. This guide should empower you to handle daily package management tasks with ease.
FAQ
- What is RPM?RPM stands for Redhat Package Manager and is a command-line tool used to manage packages in the .rpm format on Linux distributions such as CentOS, RHEL, and Fedora.
- Does RPM handle dependencies?No, RPM does not automatically manage dependencies for packages. Users need to manually handle and install any dependencies required by a package.
- Can I install a package without its dependencies?Yes, you can use the
--nodeps
option when installing a package to bypass dependency checks, although this is generally not recommended. - How do I verify if a package is installed?You can use the command
rpm -q [PACKAGE_NAME]
to check if a specific package is installed on your system.