How To Use Linux RPM Command

RPM stands for “Red Hat Package Manager.” It is a powerful package management system used primarily in Red Hat-based distributions like Red Hat Enterprise Linux (RHEL), Rocky Linux, Fedora, CentOS, Alma Linux and others. RPM command allows users to install, update, uninstall, verify, and query software packages on their Linux systems.

Here’s a detailed look at RPM in Linux:

Overview

RPM Package Manager:

  • Origin: Developed by Red Hat Inc., hence the name.
  • File Extension: .rpm
  • Purpose: Manages the installation, upgrading, and removal of software packages.

Key Features

  1. Package Management:
    • Installation: RPM handles the installation of software packages, ensuring that all necessary dependencies are met.
    • Upgrading: It allows for seamless upgrades of existing packages.
    • Uninstallation: RPM can remove installed packages while ensuring system stability.
    • Verification: It can verify the integrity and authenticity of installed packages.
  2. Database Management:
    • RPM maintains a database of installed packages, which it uses to manage and query package information.
  3. Dependency Resolution:
    • RPM packages can specify dependencies, ensuring that all required software is present for a package to function correctly.

RPM Command Syntax

Here is the basic command syntax or usage of the rpm utility:

Rpm [option(s)] PACKAGE-NAME

The RPM utility depends on options which specify what it should do when it is executed. Let’s consider some rpm command examples, using some of the options commonly used with rpm. 

Commonly Used RPM Command Options

{-a | –all} List all installed rpm packages

{-e | –erase} Uninstall (erase) Package

{-F | –freshen} Upgrade package if only an older version is available

–force Forcefully install or uninstall packages, ignoring dependencies and warnings

{-h | –harsh} Commonly used with -v to nicely display package installation progress in harsh marks

{-i | –install} Install package

–import Import GPG keys for verification of package signatures 

{-l | –list} List files rolled into a package

–nodeps Ignore dependency checks when install or uninstalling packages

{-q | –query} Query package or file. Commonly used with f and i. You will see examples later.

{-qf | –queryformat} Query format | query file | reveal package a file belongs to

–setperms Set installed files permissions according to package specifications

{-s | –state} Show the states of files listed

–test Test run without removing or installing a package

{-U | –upgrade} Upgrade package

{-v | –verbose} Print or display details. Used with -i for cleaner output

{-V | –verify} Check the authenticity of installed packages

-ev –nodeps Uninstall package without checking of dependency

-qi Display information about package, version

-qf Query package name for a file(/etc/passwd)

-qc Query configuraiton name of package

-ql List all the files of a package

-qd Query doc file

-qa –last Query all recently installed RPMs package

-qR Find out what dependencies a rpm file has

RPM Command Examples

The rpm utility is pretty straightforward to use and supports the combination of multiple options. Below are the most frequent use cases.

Package installation

RHEL packages are distributed as rpm packages and thus suffixed with the .rpm extension. Below is the command example for installing .rpm packages:

# rpm -ivh PACKAGEN-NAME

  • i install package
  • v verbose output  
  • h print package unarchiving or installation progress in 50 harsh marks

An rpm package may be released and distributed for multiple system architecture or targets, i.e x86 and x86-x64. To avoid installation issues, download the package that is target for your choice system architecture. These days, what you commonly have is the amd64 which is the same as x64. Let’s download and install the MySQL database package in the following example:

wget https://dev.mysql.com/get/mysql84-community-release-el9-1.noarch.rpm

In case you have RHEL or Rocky Linux minimal install and wget isn’t available, install it using the following command:

[root@localhost ~]# yum install wget -y –quiet                                  

After installing wget, grab the rpm package over the wire, using the wget utility. Run the following commands to download and install the .rpm package:

[root@localhost ~]# wget https://dev.mysql.com/get/mysql84-community-release-el9-1.noarch.rpm 

[root@localhost ~]# rpm -ivh mysql84-community-release-el9-1.noarch.rpm

Now that we’ve installed the MySQL database rpm package, let’s upgrade it using rpm plus the -U option:

[root@localhost ~]# rpm -Uvh mysql84-community-release-el9-1.noarch.rpm

Make sure to manually install missing dependencies required by package upgrades. RPM lists all package dependencies when the upgrade command above is executed. 

You can skip warnings and dependencies using the –nodeps option which tells rpm to ignore dependencies. For that, here is the command syntax:

[root@localhost ~]# rpm -Uvh –nodeps mysql84-community-release-el9-1.noarch.rpm

Uninstall or Erase RPM Packages

Executing rpm command with –erase or -e option removes the specified package. Below is a typical example, removing MySQL:

[root@localhost ~]# rpm -e mysql84-community-release-el9-1.noarch

Show Package Details Before Install

Below is a typical example of displaying package info before installation:

[root@localhost ~]# rpm -qip mysql84-community-release-el9-1.noarch.rpm

  • -qi – Queries information.
  • -p – Verifies a package.

Check Dependencies Before Install

The rpm command lets you check a package’s dependencies before installing it on your system. To view the list of dependencies, you must have the .rpm package downloaded locally. Here is the command for that:

[root@localhost ~]# rpm -qpR mysql84-community-release-el9-1.noarch.rpm

  • -q – Query package format
  • -p – Verify package
  • -R – list dependencies for package

List Package Installed Files

To list all files installed for a given package, execute below:

[root@localhost ~]# rpm -ql mysql84-community-release-el9-1.noarch.rpm

List All RPM Installed Packages

Here is the command for listing all the rpm packages install on a RHEL pr RHEL-based system;

[root@localhost ~]# rpm -qa

You can search for a particular package by piping the output of the above rpm command to grep and then extracting the package from the long list. Here is an example:

[root@localhost ~]# rpm -qa | grep -i mysql

RPM Command To Display A List Of Recently Installed Packages

To show the list of packages recently installed, use –last with -qa.

[root@localhost ~]# rpm -qa –last

How To Get .RPM Packages

In addition to using wget to grab packages when you have package URL, you can find and download rpm packages at rpmfind.

Leave a Reply

Your email address will not be published. Required fields are marked *