Every Linux distribution has its own way to manage software packages. CentOS uses two package management commands: a low-level RPM and a high-level YUM command.
RPM is the abbreviation for Red Hat Package Manager. Yes, it is used by Red Hat Enterprise Linux, Fedora, Oracle Linux, and Scientific Linux as well. It is used to manage packages, and in this article, I will show you some basic operations with RPM.
Package installation with RPM on CentOS
We use RPM to install a package from a .rpm file. We need to have a file, so in order to demonstrate it to you, we will download a .rpm file for a package called epel-release, which is a set of additional repositories (you can think of these as software stores) for Fedora and CentOS. It can be found at the following address:
Right-click on the epel-release-6.8.noarch.rpm and choose Copy link address. Now go to your Linux command line and download the file using curl.
Once downloaded, we can install the .rpm file by using -i option to rpm command.
Listing installed packages
Now we expect the package to be installed and available but how can we make sure it really is? Rpm command has an option to list all installed rpm packages, using the -qa option.
This will list all installed packages but we use can use grep to filter the results to only show our package. So let’s do it.
On clean CentOS 6 minimal installation, there are a lot of installed packages, and you can see their exact number by counting the lines.
If we decide that we don’t need a package anymore, we can uninstall it. It can be done using the same rpm command, only with a different option, -e, followed by a package name. Note that this is NOT the file name.
After removal, we listed installed packages, and see that there isn’t epel-release any more. Did you notice that I did not specify the full package name with the version number? Well, you don’t have to specify the version number, basic package name will suffice.
Although the usual way of installing a .rpm file is to install it from a local file system, you can also install it from a remote location. Let’s use the download link we obtained before, and just use it as if it is a physical file:
Listing package files
There is one useful option to rpm command, and that is -ql option. It lists all the files that are installed with the package. epel-release is not very interesting, so we might try to list files that belong to one installed package called openssh-server.
Package “ownership” of a file
You may ask the question: which package installed a specific file, or rather, to which package a file belongs to. Option -qf followed by a file name(full path) shows a package that installed a file.
We can get more information about the installed package like its version and release numbers, description when it was installed and so on. It is used with -qi option to rpm, followed by an installed package name.
Even more, with -qip option to rpm, we can get information about the package from the package file, before it was even installed. It is quite useful sometimes when we need to know some additional information.
The outputs look almost the same. Can you spot the difference? I’ll leave this one to you.
Not so long time ago, rpm and source installs were the main methods to install Linux software packages. Source install (compiling source files) is by default complicated and time-consuming (it can take even hours), and .rpm packages can leave you in a so-called rpm dependency hell.
Luckily, in the last few years, most of the software package producers allow you to configure your system to use the yum installer, even for latest versions of the software. This method is easier and takes care of dependencies automatically.
However, some features of rpm command are still essential to know as a Linux administrator, so getting to know more advance rpm features makes you feel more comfortable while working with Linux in the command line. Therefore rpm is definitely old but not depreciated!