RPM package queries

This post is just a quick walk-through of some basic commands to help you find information about rpm packages. These commands will work for any rpm based distribution (Red Hat, Centos, Suse, Mageia) Debian based distributions like Ubuntu or Mint use dpkg instead of rpm and I’ll cover those in a different post.

Query the rpm database

You can query the rpm database to find a particular installed package using the -q option. With rpm -q you must also pass a package name. For example, to find out what version of the httpd server we have installed we can use rpm -q httpd

rpm -q httpd

List all installed packages

To get a quick list of every installed package on an rpm based Linux distribution you can use -qa. In this case you do not need to pass any specific package into the command. Often times you will use this to find a package when you are not sure of the exact name. For example, you might grep for “ruby” to find all the installed ruby libraries.

rpm -qa

Running rpm -qa | grep ruby will produce output similar to this on a Centos 7 server.

rpm -qa | grep ruby

Find associated files

Using rpm -ql and rpm -qc will help you to locate files associated with a particular package. This is a great tool to help you find your way around a newly installed application. For example, how could you find out that the configuration file for Apache can be found at “/etc/httpd/conf/httpd.conf”, without searching the interwebs?

rpm -qc <package name> will list all of the configuration files.

 rpm -qc httpd

Similarly running rpm -ql will give you a list not only of configuration files but also every file that was installed on your server with its location.

Identify vendors

In some cases, you may need more information about a package. Who is the vendor? When was it installed? etc… Getting this type of information with rpm packages is easy.

rpm -qi <package name>

rpm -qi httpd
Name        : httpd
Version     : 2.4.6
Release     : 45.el7.centos.4
Architecture: x86_64
Install Date: Mon 12 Jun 2017 09:37:04 PM UTC
Group       : System Environment/Daemons
Size        : 9823677
License     : ASL 2.0
Signature   : RSA/SHA256, Thu 13 Apr 2017 01:04:44 AM UTC, Key ID 24c6a8a7f4a80eb5
Source RPM  : httpd-2.4.6-45.el7.centos.4.src.rpm
Build Date  : Wed 12 Apr 2017 09:05:23 PM UTC
Build Host  : c1bm.rdu2.centos.org
Relocations : (not relocatable)
Packager    : CentOS BuildSystem <http://bugs.centos.org>
Vendor      : CentOS
URL         : http://httpd.apache.org/
Summary     : Apache HTTP Server
Description :
The Apache HTTP Server is a powerful, efficient, and extensible
web server.

Finding documentation

You can also quickly find where documentation for a package can be found on your system using rpm -qd

rpm -qd httpd

This documentation will include listing man pages that migt be available. As well as example configuration files. In this case you can see that “/usr/share/doc/httpd-2.4.6/httpd-vhosts.conf” is an example of a virtual host file…. Maybe something that would come in handy as a template for virtual hosts you might have to set up.

As you can see there is quite a lot of information that can be extracted from the rpm database. In my humble opinion, this is one of the big advanatages that rpm has over dpkg (though you can get this information from dpkg, it’s just not as straight forward), rpm makes it easy to query the database and quickly find the information you need.

All of this really only scratches the surface of what you can do as well. There are many ways to modify these commands to help you discover information about the packages you have installed on your system. I encourage you to read the full man page for rpm if you are interested in learning more in-depth capabilities for rpm packages.

Luke has an RHCSA for Red Hat Enterpirse Linux 7 and currently works as a Linux Systems Adminstrator in Ohio.

This post, re-published here with permission, was originally published on Luke’s site here.

Be the first to comment

Leave a Reply

Your email address will not be published.