RPM package queries

By: Luke Rawlins Jun 12, 2017 | 4 minutes read
Share this:

Tags: CentOS, OpenSUSE, package management, rpm

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.

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
httpd-2.4.6-45.el7.centos.4.x86_64

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
rubygem-json-1.7.7-29.el7.x86_64
ruby-libs-2.0.0.648-29.el7.x86_64
rubygems-2.0.14.1-29.el7.noarch
ruby-irb-2.0.0.648-29.el7.noarch
rubygem-bigdecimal-1.2.0-29.el7.x86_64
ruby-2.0.0.648-29.el7.x86_64
rubygem-rdoc-4.0.0-29.el7.noarch
rubygem-io-console-0.4.2-29.el7.x86_64
rubygem-psych-2.0.0-29.el7.x86_64

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 will list all of the configuration files.

 rpm -qc httpd
/etc/httpd/conf.d/autoindex.conf
/etc/httpd/conf.d/userdir.conf
/etc/httpd/conf.d/welcome.conf
/etc/httpd/conf.modules.d/00-base.conf
/etc/httpd/conf.modules.d/00-dav.conf
/etc/httpd/conf.modules.d/00-lua.conf
/etc/httpd/conf.modules.d/00-mpm.conf
/etc/httpd/conf.modules.d/00-proxy.conf
/etc/httpd/conf.modules.d/00-systemd.conf
/etc/httpd/conf.modules.d/01-cgi.conf
/etc/httpd/conf/httpd.conf
/etc/httpd/conf/magic
/etc/logrotate.d/httpd
/etc/sysconfig/htcacheclean
/etc/sysconfig/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.

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

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.

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

rpm -qd httpd
/usr/share/doc/httpd-2.4.6/ABOUT_APACHE
/usr/share/doc/httpd-2.4.6/CHANGES
/usr/share/doc/httpd-2.4.6/LICENSE
/usr/share/doc/httpd-2.4.6/NOTICE
/usr/share/doc/httpd-2.4.6/README
/usr/share/doc/httpd-2.4.6/VERSIONING
/usr/share/doc/httpd-2.4.6/httpd-dav.conf
/usr/share/doc/httpd-2.4.6/httpd-default.conf
/usr/share/doc/httpd-2.4.6/httpd-info.conf
/usr/share/doc/httpd-2.4.6/httpd-languages.conf
/usr/share/doc/httpd-2.4.6/httpd-manual.conf
/usr/share/doc/httpd-2.4.6/httpd-mpm.conf
/usr/share/doc/httpd-2.4.6/httpd-multilang-errordoc.conf
/usr/share/doc/httpd-2.4.6/httpd-vhosts.conf
/usr/share/doc/httpd-2.4.6/proxy-html.conf
/usr/share/man/man8/apachectl.8.gz
/usr/share/man/man8/fcgistarter.8.gz
/usr/share/man/man8/htcacheclean.8.gz
/usr/share/man/man8/httpd.8.gz
/usr/share/man/man8/rotatelogs.8.gz
/usr/share/man/man8/suexec.8.gz

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.

Related Posts


Command not found!

So you’re running through some instructions to configure software on your system, or troubleshoot some problem with a service and you see an error at the command line that says “command not found”. Here is how to locate the packages you need to install in order to use commands that are not available on your system. CentOS/Red Hat - yum provides Yum is an excellent package manager with lots of great built in functions. Read more

Managing packages with zypper

Suse Enterprise Linux and it’s upstream community distro openSUSE use a package manager called “zypper”. Zypper is a fast easy to use package management tool. In my opinion, zypper is hands down the best package manager out there. It provides meaningful, easy to read output, it resolves package dependencies quickly, and it has a cool name. Zypper has many options that can be abbreviated; install (in), search (se), info (if), update (up) and lots of others. Read more

openSUSE patch vs update

If you dig into the man pages for zypper, you will notice that zypper provides three distinct options for keeping your openSUSE system up-to-date; update (up), patch, and dist-upgrade (dup). If you aren’t familiar with zypper see my previous post managing packages with zypper for more information. In this post I will attempt to demonstrate the differences between each option and suggest when you may want to consider using each. In particular, I will try to explain the difference between a simple update and a patch, with emphasis on how to gather detailed information on particular patches. Read more


Contact

If you’d like to get in touch, contact with me via email - or follow on Twitter.

[email protected]