What is the rpm command & how to use it?

In this article, you will learn about what is the rpm command in Linux and how to use it?

The rpm stands for RedHat Package Manager. It is an open-source package management utility for Red Hat-based systems. You can find this utility in Fedora, RHEL, and Centos. This tool helps to install, update, uninstall, re-install, verify, query, and manage system software packages in Linux operating system.

This utility only works with packages that are built for processing by the rpm package. The rpm was known as the .rpm file, and this includes compiled software programs and libraries needed by the packages. The RPM maintains a database of installed packages and their files, so you can query and verify with the help of rpm on your system.

There is some important and day-to-day use of the rpm command.

Check the PGP signature

You can use rpm to check the PGP signature of packages before going to install them on the Linux system. It will make sure the package’s integrity.

rpm --checksig package_name

For example, I’m checking the PGP signature of the package postfix,

rpm --checksig postfix-2.10.1-7.el7.x86_64.rpm
rpm command
Checking PGP signature of postfix

Check rpm package dependencies before installing

You can use this command to check the package dependencies before installing any package.

rpm -qpR package_name

Here,

-q: Query a package
-p: List capabilities this package provides.
-R: List capabilities on which this package depends.

For example, I’m checking the dependency of rpm package python,

rpm -qpR python-2.7.5-76.el7.x86_64.rpm
rpm command
Checking package dependencies.

Installation of the rpm package

So, if you have a .rpm package and you want to install it then the below command will help you to install that package.

rpm -ivh package_name

Here,
-i: install a package
-v: verbose for a nicer display
-h: print hash marks as the package archive is unpacked.

For example, I’m installing a program name postfix (note: you have to give the absolute path for that program or you can go inside that directory where that program is located, here I’m inside the program file directory so I’m not giving the absolute location).

rpm -ivh postfix-2.10.1-7.el7.x86_64.rpm
rpm -ivh command
Installing a package using the rpm -ivh command

Checking installed rpm package using the rpm command

You can also use this command to check the installed rpm package using the -qa argument.

rpm -qa package_name

Here,

-q: for query and -a: for all

For example, I am checking a package name postfix

Command: rpm -qa postfix
rpm -qa command
Checking a package name.

Listing all the files of an installed rpm package

You can use this command to get all the files related to the installed rpm package.

rpm -ql package_name

Here, -ql stands for query list.

Let’s take an example, If you want to check all files for package python then

Command: rpm -ql python

List recently installed rpm packages

You can use the rpm command along with -qa and –last to get the recently installed package list and grep it with fewer commands so you can look pagewise.

rpm -qa --last | less

Upgrade an rpm package

If you want to upgrade a package that is already installed then you can use the command.

rpm -Uvh package name

Here, -U stands for upgrade

Note: When we use the rpm command to upgrade, it upgrades the package and also puts a backup of the old package.

Uninstall or remove a package using rpm command

Also, you can use this command to remove a package.

rpm -evh package_name

Here, -e stands for erasing.

For example, I’m uninstalling a package whose name is postfix,

rpm -evh postfix
rpm -evh command
Removing a package

Query a file that belongs to which rpm package using the rpm command

You can find the file with the rpm command using -qf arguments.

rpm -qf file_name

Here, -qf stands for query file

For example, I’m checking the file name passwd package name.

rpm -qf /etc/passwd
rpm -qf
Querying file name

Query information of installed rpm package using the rpm command

rpm -qi package_name

Here, -qi stands for query information (Information about installed package).

For example, I’m checking the package information of the postfix

rpm -qi postfix
-qi
Checking the package information of postfix

Information about the package before installing using rpm command

rpm -qip package_name

Here, -qip: for query info package, (this helps to get the information of downloaded package)

Documentation query of the installed rpm package

If you want to get the documentation so you can use the below command.

rpm -qdf package_name

Here, -qdf: for query document file, (To get the list of available documentation of an installed package).

For example, I’m checking the documents of the yum package

rpm -qdf /usr/bin/yum
 -qdf
Checking the documents of the yum package

List all the configuration file of an installed package

So, The below command will bring all the configuration related files,

rpm -qc package_name

Here, -qc: the query of configuration

For example, I’m querying of configuration for the postfix program.

rpm -qc postfix
 -qc
Querying of configuration for the postfix program

Note: I always suggest reading the manual page and help. It will give you an in-depth introduction to the command.

So, to get the manual page type the below command,

man rpm

But, to get the only command options, you can type the below command.

rpm --help

Conclusion

In conclusion, you learned about rpm, and you can see that it is easy to use, and you get a lot of information. The yum allows for automatic updates packages and dependency management on RPM-based distributions. So, I hope, you understand, but if you have any questions, you can ask in the comment section. 

You may like to read about What is the yum command & how to use it?

Also, How to setup passwordless ssh login

One comment

Leave a Reply

Your email address will not be published.