RPM Command in Linux Explained with Examples

Red Hat packs software in packages. It uses the .rpm extension for packages. A package includes binary files, script files, configuration files, documentation files, and installation instructions for a particular software application. The rpm command allows us to query installed packages, install new ones, and update or remove existing ones. This tutorial explains how to use it for package management.

RPM File Naming Convention

A package file name provides information about the version, release, and the hardware architecture. The following is a package file name.

vsftpd-3.0.5-6.el9.x86_64.rpm

The following table explains the information it contains.

vsftpdIt is the package name.
3.0.5It is the main version of the package.
6 It is the subversion of the main version.
el9 It is the RHEL version.
x86_64 It represents hardware architecture.
rpm It is the file extension.

A package name

Selecting the right package for the installation

A package includes binary files for a specific hardware platform and RHEL version. When installing, ensure it matches the targeted hardware platform and the RHEL version. The following command displays the hardware architecture.

#uname -i
Use the following command to view the RHEL version.
#cat /etc/redhat-release

package version and architecture

Essential options

The rpm command supports numerous options and arguments. The following table lists essential options and their functions.

Option Description
-qPerform a query operation
-aList all installed packages
-cList all configuration files of the package
-dList all documentation files of the package
-RList all dependent packages
-iProvide information about the package
-lList all files of the package
--scriptsList all scripts of the package
-fFind the package that belongs to the specified file
-pPerform a query in the individual package instead of the RPM database

All options

You can check the help section or read the manual pages for this command to learn about the functions of all options. The following command shows the help section of this command.

#rpm --help

the help option

Viewing all installed packages

The following command lists all installed packages.

#rpm -qa

listing all installed packages

Querying for a specific package

To query for a particular package, specify its name as an argument.

#rpm -qa [Package Name]

For example, use the following commands to query for the vsftpd and httpd packages.

#rpm -qa vsftpd
#rpm -qa httpd

Query for a specific package

You can use the grep command to find specific packages in the output. For example, use the following command to list all installed packages that contain the word 'arp' in their names.

#rpm -qa | grep arp

Using the grep command

Getting information on a specific package

The i option shows detailed information about the specified package. This information includes the name, version, release, architecture, installation date, group, size, license type, signature, build date, host, URL, summary, and description.

#rpm -qi httpd

Showing information about a package

By default, the rpm command performs the query operation on the packages installed on the system. The '-p' option allows you to perform it on any package. The '--scripts' option lists all scripts of the package. You can combine both options and use them to query about a package before installing it. It lets you know what a package includes and what it will do after the installation. The following command performs the query operation on a package available on the RHEL installation disk.

#rpm -qpi  --scripts vsftpd-3.0.5-6.el9.x86_64.rpm

viewing package files

Finding a command's package and its files

When you hit the Enter key after typing a command on the shell prompt, the shell finds the main configuration or script file of that command and executes it. You can use the which command to view the path of this file. For example, the following command displays the path of the main configuration or script file for the ssh command.

#which ssh

You can use the output of the above command to find the package that provides or installs that file. The -f option shows the package that provides the given file. The following command displays the package that provides the main script file for the ssh command.

#rpm -qf /usr/bin/ssh

Once you know the package name, you can list all configuration files associated with it. The -c option shows all configuration files of a package.

#rpm -qc openssh-clients-8.7p1-43.el9.x86_64

A package also includes documentation or manual files. The -d option shows all documentation files. These files provide detailed information about the package's functionalities, options, and features. The man command shows these pages.

#rpm -qd openssh-clients-8.7p1-43.el9.x86_64

showing configuration files

The -l option shows all files of a package, including configuration and documentation.

#rpm -ql openssh-clients-8.7p1-43.el9.x86_64

listing all files of package

Installing packages

The -i option installs the given package. Generally, administrators use it with the -v and -h options. The -v option shows verbose. The -h option shows real-time progress of the process.

#rpm -ivh [package-path]

Installing a package

Removing packages

The -e option deletes the given package. You can use it with the -v and -h options to view the real-time updates of the removal process.

#rpm -evh [package-name]

When using the above command, do not specify the .rpm extension with the package name. If you do, it returns the 'package is not installed' error. You can provide only the package name or include version and platform information with the name. For example, use the following command to remove the vsftpd package.

#rpm -evh vsftpd

removing a package

If you do not want to display real-time updates, omit the -v and -h options. For example, use the following command to install the package.

#rpm -i [package-path]

To remove the package, use the following command.

#rpm -e [package-name]

installing and removing packages

Installing a package forcefully

The rpm command does not install a package that depends on other packages unless those packages are already installed on the system. If dependencies are not present, it returns the following error.

Error: Failed dependencies:
	[package] is needed by [package]

dependencies error

To install the package without installing dependencies, use the --nodeps and --force options. When used, these options instruct the rpm command to install the given package without checking its dependencies.

the --nodeps option

RPM, YUM, and DNF

RHEL provides three tools for package management. There are rpm, yum, and dnf. RPM is the oldest, and DNF is the newest in this list. In earlier versions, RPM was the only available tool for package management. There are two types of packages: independent and dependent. Independent packages are standalone. You can install and use them separately. Dependent packages rely on other packages to provide specific functionality. Unless you install those packages first, dependent packages do not work as expected. If a package requires other packages to function, the rpm command displays their names. However, it does not have built-in functionality to install them with the package. You must install them separately before the package. It makes package management complex and harder.

The yum tool solves this issue. The yum utility finds all dependent packages and installs them with the package. With it, you can install any package with a single command. If a package needs other packages for any functionality, it automatically installs them with the package. The yum utility solves dependency issues. However, it lacks many modern features. The dnf provides them, in addition to all the functions of yum. It includes all the things modern Linux systems need. It is the default package management utility on RHEL.

The following tutorial explains how to use the dnf command for package management.
The dnf command explained

The dnf tool is the direct replacement of the yum utility. If you have dnf, you do not need yum. However, it is not designed to replace the rpm command. The rpm command provides functions that are not part of the dnf tool. You can use the rpm command in the following situations.

  • If repositories are not present, you cannot use the yum or dnf commands. In that case, the rpm command is the only option.
  • The rpm command does not depend on any particular source for packages. You can use it to install packages obtained from any source. You can create your RPM and use it to install that.
  • The rpm command supports various query options. You can use them to get information about packages before and after installing them.

Conclusion

Package management is an essential system administration task. This tutorial explains how to use the rpm command for it. It describes the options and arguments you need to manage packages effectively with this command.

ComputerNetworkingNotes Linux Tutorials RPM Command in Linux Explained with Examples

We do not accept any kind of Guest Post. Except Guest post submission, for any other query (such as adverting opportunity, product advertisement, feedback, suggestion, error reporting and technical issue) or simply just say to hello mail us ComputerNetworkingNotes@gmail.com