Bookmark this page

Explain and Investigate RPM Software Packages

Objectives

Explain how software is provided as RPM packages, and investigate the DNF and RPM installed system packages.

Software Packages and RPM

The RPM Package Manager, which Red Hat originally developed, provides a standard way to package software for distribution. Managing software in the form of RPM packages is simpler than working with software that is extracted to a file system from an archive. With RPM packages, administrators can track which files the software package installs, which files the software package removes if you uninstall it, and it verifies that supporting packages are present when you install it. The local RPM database on your system stores the information about installed packages. Red Hat provides all software for Red Hat Enterprise Linux as an RPM package.

RPM package file names consist of four elements (plus the .rpm suffix): name-version-release.architecture:

Figure 12.3: RPM file name elements
  • NAME is one or more words to describe the contents (coreutils).

  • VERSION is the version number of the original software (8.32).

  • RELEASE is the release number of the package based on that version, and is set by the packager, who might not be the original software developer (31.el9).

  • ARCH is the processor architecture that the package is compiled to run on. The x86_64 value indicates that this package is built for the 64-bit version of the x86 instruction set (as opposed to aarch64 for 64-bit ARM, and so on).

RPM packages are often downloaded from repositories. A repository is a central location for storing and maintaining RPM software packages.

You require only the package name to install RPM packages from repositories.

  • If multiple versions exist, then the RPM Package Manager installs the package with the later version number.

  • If multiple releases of a single version exist, then the RPM Package Manager installs the package with the later release number.

Each RPM package is an archive with the following components:

  • The files that the package installs in your system.

  • Information about the package (metadata), such as the name, version, release, and architecture; a summary and description of the package; whether it requires other packages to be installed; licensing; a package change log; and other details.

  • Scripts that might run when you install, update, or remove the package. These scripts might also run when you install, update, or remove other packages.

Typically, software providers digitally sign RPM packages with GPG (GNU Privacy Guard) keys. (Red Hat digitally signs all packages that it releases.) The RPM system verifies package integrity by confirming that the package is signed with the appropriate GPG key. The RPM system fails to install a package if the GPG signature does not match.

Update Software with RPM Packages

Red Hat generates a complete RPM package to update software. An administrator who installs that package gets only the most recent version of the package. You do not need to install an earlier version of a package to patch it. To update software, RPM removes the earlier version of the package and installs the latest version. Updates usually retain configuration files, but the packager of the new version defines the exact behavior.

Typically, only one version of a package is installed at a time. If a package is built with non-conflicting file names, then you might install multiple versions. The kernel package is a an example of installing multiple package versions. Because you test a new kernel only by booting to that kernel, the package is designed to support installing multiple versions. If the new kernel fails to boot, then you can revert to the previous kernel.

Examine RPM Packages

The rpm utility is a low-level tool that can retrieve information about the contents of package files and installed packages. By default, the tool gets information from a local database of installed packages. Use the rpm command -p option to get information about a downloaded but uninstalled package file. Use this option to inspect the package contents before installing.

Retrieve general information about installed packages:

  • rpm -qa : List all installed packages.

  • rpm -qf FILENAME : Determine which package provides FILENAME.

[user@host ~]$ rpm -qf /etc/yum.repos.d
redhat-release-9.1-1.0.el9.x86_64

Get information about specific packages:

  • rpm -q : List the currently installed package version.

[user@host ~]$ rpm -q dnf
dnf-4.10.0-4.el9.noarch
  • rpm -qi : Get detailed package information.

  • rpm -ql : List the files that the package installs.

[user@host ~]$ rpm -ql dnf
/usr/bin/dnf
/usr/lib/systemd/system/dnf-makecache.service
/usr/lib/systemd/system/dnf-makecache.timer
/usr/share/bash-completion
/usr/share/bash-completion/completions
/usr/share/bash-completion/completions/dnf
...output omitted...
  • rpm -qc : List only the configuration files that the package installs.

[user@host ~]$ rpm -qc openssh-clients
/etc/ssh/ssh_config
/etc/ssh/ssh_config.d/50-redhat.conf
  • rpm -qd : List only the documentation files that the package installs.

[user@host ~]$ rpm -qd openssh-clients
/usr/share/man/man1/scp.1.gz
/usr/share/man/man1/sftp.1.gz
/usr/share/man/man1/ssh-add.1.gz
/usr/share/man/man1/ssh-agent.1.gz
...output omitted...
  • rpm -q --scripts : List the shell scripts that run before or after you install or remove the package.

[user@host ~]$ rpm -q --scripts openssh-server
preinstall scriptlet (using /bin/sh):
getent group sshd >/dev/null || groupadd -g 74 -r sshd || :
getent passwd sshd >/dev/null || \
  useradd -c "Privilege-separated SSH" -u 74 -g sshd \
  -s /sbin/nologin -r -d /usr/share/empty.sshd sshd 2> /dev/null || :
postinstall scriptlet (using /bin/sh):

if [ $1 -eq 1 ] && [ -x "/usr/lib/systemd/systemd-update-helper" ]; then
    # Initial installation
    /usr/lib/systemd/systemd-update-helper install-system-units sshd.service sshd.socket || :
fi
...output omitted...
  • rpm -q --changelog : List the change log information for the package.

[user@host ~]$ rpm -q --changelog audit
* Tue Feb 22 2022 Sergio Correia <scorreia@redhat.com> - 3.0.7-101
- Adjust sample-rules dir permissions
  Resolves: rhbz#2054432 - /usr/share/audit/sample-rules is no longer readable by non-root users

* Tue Jan 25 2022 Sergio Correia <scorreia@redhat.com> - 3.0.7-100
- New upstream release, 3.0.7
  Resolves: rhbz#2019929 - capability=unknown-capability(39) in audit messages
...output omitted...

Query local package files:

  • rpm -qlp : List the files that the local package installs.

[user@host ~]$ ls -l podman-4.0.0-6.el9.x86_64.rpm
-rw-r--r--. 1 student student 13755101 Mar 22 11:35 podman-4.0.0-6.el9.x86_64.rpm2637-15.el9.x86_64.rpm
[user@host ~]$ rpm -qlp podman-4.0.0-6.el9.x86_64.rpm
/etc/cni/net.d
/etc/cni/net.d/87-podman-bridge.conflist
/usr/bin/podman
...output omitted...

Install RPM Packages

Use the rpm command to install an RPM package that you downloaded to your local directory.

[root@host ~]# rpm -ivh podman-4.0.0-6.el9.x86_64.rpm
Verifying...                          ################################# [100%]
Preparing...                          ################################# [100%]
Updating / installing...
        podman-2:4.0.0-6              ################################# [100%]

Warning

Be careful when installing packages from third parties, not just because of the software that the packages might install, but because the RPM package might include arbitrary scripts that run as the root user as part of the installation process.

Extracting RPM packages

Use the rpm2cpio command to extract files from an RPM package file without installing the package.

The rpm2cpio command converts an RPM package to a cpio archive. After the RPM package is converted to a cpio archive, the cpio command can extract a list of files.

Use the cpio command with the -i option to extract files from standard input. Use the -d option to create subdirectories as needed, starting in the current working directory. Use the -v option for verbose output.

[user@host tmp-extract]$ rpm2cpio httpd-2.4.51-7.el9_0.x86_64.rpm | cpio -idv
./etc/httpd/conf
./etc/httpd/conf.d/autoindex.conf
./etc/httpd/conf.d/userdir.conf
./etc/httpd/conf.d/welcome.conf
./etc/httpd/conf.modules.d
./etc/httpd/conf.modules.d/00-base.conf
./etc/httpd/conf.modules.d/00-dav.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.modules.d/README
./etc/httpd/conf/httpd.conf
...output omitted...
9774 blocks
[user@host tmp-extract]$ ls -l
total 1552
drwxr-xr-x. 5 user user       55 Feb  3 15:06 etc
-rw-r--r--. 1 user user  1588633 Feb  3 15:06 httpd-2.4.51-7.el9_0.x86_64.rpm
drwxr-xr-x. 3 user user       19 Feb  3 15:06 run
drwxr-xr-x. 7 user user       70 Feb  3 15:06 usr
drwxr-xr-x. 5 user user       41 Feb  3 15:06 var

Extract individual files by specifying the path of the file:

[user@host ~]$ rpm2cpio httpd-2.4.51-7.el9_0.x86_64.rpm | cpio -id "*/etc/httpd/conf/httpd.conf"
9774 blocks
[user@host ~]$ ls etc/httpd/conf/
httpd.conf

Use the rpm2cpio and cpio -t commands to list the files in an RPM package. Use the -v option of the cpio command for verbose output.

[student@servera ~]$ rpm2cpio httpd-2.4.51-7.el9_0.x86_64.rpm | cpio -tv
drwxr-xr-x   1 root     root            0 Mar 21  2022 ./etc/httpd/conf
-rw-r--r--   1 root     root         2893 Mar 21  2022 ./etc/httpd/conf.d/autoindex.conf
-rw-r--r--   1 root     root         1252 Mar 21  2022 ./etc/httpd/conf.d/userdir.conf
-rw-r--r--   1 root     root          653 Mar 21  2022 ./etc/httpd/conf.d/welcome.conf
drwxr-xr-x   1 root     root            0 Mar 21  2022 ./etc/httpd/conf.modules.d
-rw-r--r--   1 root     root         3372 Mar 21  2022 ./etc/httpd/conf.modules.d/00-base.conf
-rw-r--r--   1 root     root          139 Mar 21  2022 ./etc/httpd/conf.modules.d/00-dav.conf
-rw-r--r--   1 root     root          948 Mar 21  2022 ./etc/httpd/conf.modules.d/00-mpm.conf
-rw-r--r--   1 root     root          787 Mar 21  2022 ./etc/httpd/conf.modules.d/00-optional.conf
-rw-r--r--   1 root     root         1073 Mar 21  2022 ./etc/httpd/conf.modules.d/00-proxy.conf
-rw-r--r--   1 root     root           88 Mar 21  2022 ./etc/httpd/conf.modules.d/00-systemd.conf
-rw-r--r--   1 root     root          367 Mar 21  2022 ./etc/httpd/conf.modules.d/01-cgi.conf
-rw-r--r--   1 root     root          496 Mar 21  2022 ./etc/httpd/conf.modules.d/README
-rw-r--r--   1 root     root        12005 Mar 21  2022 ./etc/httpd/conf/httpd.conf
...output omitted...
9774 blocks

 

References

rpm(8), rpm2cpio(8), cpio(1), and rpmkeys(8) man pages

Revision: rh124-9.0-398f302