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.
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-188.8.131.528-29.el7.x86_64 rubygems-184.108.40.206-29.el7.noarch ruby-irb-220.127.116.118-29.el7.noarch rubygem-bigdecimal-1.2.0-29.el7.x86_64 ruby-18.104.22.1688-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 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 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.
If you’d like to get in touch, contact with me via email - or follow on Twitter.