RPM Command Tutorial In Linux

The RPM command is created to manage packages. The RPM name comes from Red Hat Package Manager where created to manage Red Hat distribution packages. Even created for Red Hat distribution it has been widely used by different distributions where some of them based Red Hat. Red Hat, Fedora, CentOS, OpenSUSE, Oracle use the rpm package manager.

rpm Command Syntax

The RPM command has the following syntax. The package file is provided as the last parameter like below.

rpm OPTION PACKAGE
  • OPTION is used to set different operations for the specified package etc.
  • PACKAGE is the package with *.rpm extension. This parameter is optional where in some cases the rpm command may not require a package like listing installed packages.

rpm Command Help

The rpm command help information can be listed in different ways. The man command can be used to print complete help information with all options and features.

$ man rpm

More simple and single-line help information can be displayed with the -? or --help options.

$ rpm -?
rpm command help

Install-Package with rpm

The most popular use case with the rpm command is installing an RPM package or file. The -ivh options are used to install packages where the -i option is for installing, -v option to verbose output and -h for the print hash progress bar.

$ rpm -ivh nmap.rpm

Install-Package providing URL

The rpm command provides practical features like installing an RPM via URL by downloading it automatically. In the following example, we will install the rpm package by using its URL.

$ rpm -ivh https://linuxtect.com/nmap.rpm

Upgrade Package

An rpm package may be already installed and we may need to update or upgrade it. The -U option is used to upgrade the already installed package. In the following example, we upgrade the nmap.rpm package.

$ rpm -Uvh nmap.rpm

Install-Package without Dependencies

By default, a package may have some dependencies and these dependencies should be met during installation. The regular installation checks these dependencies and then completes the installation. But we can prevent this dependency check with the --nodeps option.

$ rpm -ivh --nodeps nmap.rpm

Remove/Delete Package

The rpm command can be also used to remove or delete or erase an installed package. The -e option is used for this operation. There is no need to provide an extra option for the removal of the package.

$ rpm -e nmap.rpm

Remove/Delete Package without Deleting Dependencies

By default, the package removal also removes or deletes all related dependencies. But we can prevent dependency removal with the --nodeps option.

$ rpm -evh --nodeps nmap.rpm

Query Package

We can query a package whether it is installed or not by using the -q option. Also, the package name should be provided. If the package is installed the complete package name is displayed with the version information. In the following example, we query for the tmux package.

$ rpm -q tmux
tmux-3.1c-1.fc33.x86_64

Query Detailed Information About Package

More detailed information about a package can be displayed with the -qi options.

$ rpm -qi tmux

The output is like below where information like version, release, architecture, install date, size, license, URL, description is listed.

Name        : tmux
Version     : 3.1c
Release     : 1.fc33
Architecture: x86_64
Install Date: Mon 07 Feb 2022 10:19:24 PM +03
Group       : Unspecified
Size        : 934708
License     : ISC and BSD
Signature   : RSA/SHA256, Mon 04 Jan 2021 10:15:03 PM +03, Key ID 49fd77499570ff31
Source RPM  : tmux-3.1c-1.fc33.src.rpm
Build Date  : Mon 04 Jan 2021 10:10:53 PM +03
Build Host  : buildvm-x86-15.iad2.fedoraproject.org
Packager    : Fedora Project
Vendor      : Fedora Project
URL         : https://tmux.github.io/
Bug URL     : https://bugz.fedoraproject.org/tmux
Summary     : A terminal multiplexer
Description :
tmux is a "terminal multiplexer."  It enables a number of terminals (or
windows) to be accessed and controlled from a single terminal.  tmux is
intended to be a simple, modern, BSD-licensed alternative to programs such
as GNU Screen.

The rpm command can be also used to list all related files for the specified package. The -lq options are used for this operation.

$ sudo rpm -ql tmux
List All Files Related with Install Package

An rpm package consists of multiple files. We can find the rpm package name via specifying a file. The -qf the option is used to print the package name for the specified file.

$ rpm -qf /usr/share/doc/tmux/example_tmux.conf

List All Installed Packages

The rpm command can be used to list all installed packages by using the -qa options.

$ rpm -qa
List All Installed Packages

Leave a Comment