| by Arround The Web | No comments

How to Use RPM Command in Linux

If you’re a Linux user, you’ve likely come across the term RPM. RPM is an acronym for Red Hat Package Manager, and it is a powerful command-line tool for managing software packages on Linux systems. This article will cover everything you need to know about the RPM command in Linux, including its syntax, usage, and some common examples.

  1. What is the RPM Command
  2. RPM Command Syntax
  3. RPM Command Options
  4. Install RPM Packages
  5. Upgrade RPM Packages
  6. Remove RPM Packages
  7. List Installed RPM Packages
  8. Display Package Information Before Installing
  9. Display Package Information After Installing
  10. Check Package Dependencies Before Installing
  11. List All Files of an Installed Package
  12. RPM Command in Different Linux Distros

1: What is the RPM Command

The RPM command is a software management tool for Linux operating systems. It is used to manage the installation, removal, verification, and upgrading of software packages. RPM is designed to work with packages that are in the RPM format, which is a binary format that contains all the files necessary for installing and running the software.

2: RPM Command Syntax

The basic syntax of the RPM command is as follows:

rpm [OPTIONS] [PACKAGE]

Here, [OPTIONS] refers to the command options that you can pass to the RPM command, and [PACKAGE] refers to the package that you want to manage.

3: RPM Command Options

To check the complete list of command options, run:

sudo rpm –help

Text Description automatically generated

Here are some commonly used options for the RPM command:

-i: install a package

-U: upgrade a package

-e: erase/remove a package

-q: query a package

-V: verify a package

-F: freshen an installed package

-h: display help for a specified RPM command

-v: verbose mode (displays more detailed output)

–test: test mode (simulate the specified command without performing it)

–nodeps: skip dependency checks when installing, upgrading, or removing a package

Note that there are many more options available for the RPM command, and you can find a complete list in the RPM manual page by running man rpm in your terminal.

man rpm

Graphical user interface, text, application, email Description automatically generated

4: Install RPM Packages

To install an RPM package using the rpm command, follow this syntax:

sudo rpm -ivh [Package]

This command includes the options

  • -i for install
  • -v for verbose output
  • -h to print hash marks to indicate the progress of the installation process

Before installing, ensure that you have downloaded the appropriate package file compatible with your system architecture.

For example, to install the vim-enhanced rpm package, use the following command:

sudo rpm -ivh vim-enhanced-7.4.629-8.el7_9.x86_64.rpm

We can also install an RPM package with download link using the following command:

sudo rpm -ivh [Package_URL]

5: Upgrade RPM Packages

During an RPM upgrade, the current version of the package is uninstalled, and the latest version is installed.

The following command can be used to upgrade packages:

sudo rpm -Uvh [Package]

This command includes the options

  • -U (upgrade)
  • -v (verbose mode)
  • -h (print hash marks to show upgrading process)

To upgrade vim-enhanced, use:

sudo rpm -Uvh vim-enhanced-7.4.629-8.el7_9.x86_64.rpm

Graphical user interface, text, application Description automatically generated

Manually installing additional dependencies may be required if the new version requires them. In the output after running the command, RPM shows the required dependencies that are missing.

Add the –nodeps option to the command to ignore the message and update without dependencies:

sudo rpm -Uvh --nodeps [Package]

6: Remove RPM Packages

To remove RPM packages, run:

sudo rpm -e [Package]

For example, to remove the vim-enhanced RPM, run:

sudo rpm -e vim-enhanced

Using yum is another option for uninstalling RPM packages.

sudo yum remove [Package]

For example, to remove vim using yum command run:

sudo yum remove vim-enhanced.x86_64

7: List Installed RPM Packages

Run the following command to list all installed RPM packages:

sudo rpm -qa

The command includes the -qa option, which instructs RPM to query all.

8: Display Package Information Before Installing

Before installing a package, the following command displays information about the RPM package:

sudo rpm -qip [Package]

To obtain information about a package and confirm its validity, use the options:

  • -qi (query information)
  • -p (query/verify a package)

For example, to display the information related to vim-enhanced RPM package run:

sudo rpm -qip vim-enhanced-7.4.629-8.el7_9.x86_64.rpm

Text Description automatically generated

9: Display Package Information After Installing

An RPM package’s available information can be viewed by using the -qi option, which instructs the program to query the package details:

sudo rpm -qi [Package]

The output gives us information such as package details.

For example, the following command will give us info related to vim-enhanced:

sudo rpm -qi vim-enhanced

Graphical user interface, text Description automatically generated

10: Check RPM Package Dependencies Before Installing

The RPM commands also allow us to check the dependencies of packages before we can install them. Make sure the RPM package is already downloaded for which you want to see the list of dependencies.

The command syntax we use is:

rpm -qpR [Package]

Following is the list of options this command includes:

  • -q (query format)
  • -p (query/verify a package)
  • -R (list package dependencies)

For example, to list all required dependencies by vim-enhanced package you can run:

rpm -qpR vim-enhanced-7.4.629-8.el7_9.x86_64.rpm

Graphical user interface, text, application, email Description automatically generated

11: List All Files of an Installed Package

We can also list all the files associated with a package using -ql option, this will instruct RPM to query the list:

sudo rpm -ql [Package]

For example, we can list vim-enhanced rpm package files using:

sudo rpm -ql vim-enhanced

Graphical user interface, text, application Description automatically generated

12: RPM Command in Different Linux Distros

While the RPM command works similarly across different Linux distributions, there may be some differences in usage and syntax. Here’s a brief overview of RPM commands in different Linux distros:

RPM Package Management in Red Hat-Based Systems

In Red Hat-based systems, RPM is the default package manager. The RPM package management system is used to manage software packages in these systems. To install a package in a Red Hat-based system, you can use the following command:

sudo yum install [PACKAGE]

To remove a package, you can use the following command:

sudo yum remove [PACKAGE]

RPM Package Management in Debian-Based Systems

In Debian-based systems, the default package manager is apt. However, you can still use RPM to manage packages in these systems.

RPM is a package manager for the Red Hat system so by default it is not installed on Debian. To install the RPM package manager in a Debian-based Linux system, run:

sudo apt install rpm

Text Description automatically generated

sudo apt install alien

To install a package in a Debian-based system using RPM, you can use the following command:

sudo alien -i [PACKAGE.rpm]

Note: The alien utility will convert the RPM package to deb, which you can install using the following command:

sudo apt install ./<deb_file>

RPM Package Management in Arch-Based Systems

In Arch-based systems, the default package manager is pacman. However, you can still use RPM to manage packages in these systems. To install a package in an Arch-based system using RPM, you can use the following command:

sudo pacman -U [PACKAGE.rpm]

Conclusion

The RPM command is a powerful tool for managing software packages in Linux. Whether you’re installing new packages, upgrading existing ones, or removing old ones, RPM makes it easy to keep your system up-to-date and running smoothly. By following the tips and tricks mentioned in this article, you can become proficient in using the RPM command for managing software packages.

Share Button

Source: linuxhint.com

Leave a Reply