RHCSA – Query packages before installing them


By the end of this article you should be able to answer the following questions:


You can find all my latest posts on medium.

What is the command to download a package called 'tree' without installing it?

$ yum install tree # followed by the ‘d’ option when prompted.

What is the command to query the list of files stored inside the file 'tree.rpm'?

$ rpm -qpl tree.rpm

In the last lesson we saw that the rpm command can be used to query installed packages, or individuel rpm files.

However the rpm command doesn’t know anything about yum repos, so you can’t use rpm to look up info about a package that is available in a yum repo (but hasn’t been installed yet).

The second approach is the better approach. That’s becuase you can use yum to just download a .rpm file from a repo, then using all the power of rpm (with the “p” option enabled) to query that file.

To download an rpm, all you need to do is use yum’s install command, and then select the (d)ownload option when prompted (instead of the yes or no options):

$ find /var/cache/ -name tree*              # quick check that .rpm doesn't exist yet. 
$ yum install tree
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base:
 * epel:
 * extras:
 * updates:
Resolving Dependencies
--> Running transaction check
---> Package tree.x86_64 0:1.6.0-10.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

 Package             Arch         Version           Repository          Size
 tree                x86_64       1.6.0-10.el7      base                46 k

Transaction Summary
Install  1 Package

Total download size: 46 k
Installed size: 87 k
Is this ok [y/d/N]: d
Background downloading packages, then exiting:
tree-1.6.0-10.el7.x86_64.rpm                                             |  46 kB  00:00:00
exiting because "Download Only" specified
$ find /var/cache/ -name tree*

As you can see, when you select yum’s download option, it downloads the file somwhere inside the /var/cache directory.

Now we cna query the file using rpm (along with the “p” option)

$ rpm -qpl /var/cache/yum/x86_64/7/base/packages/tree-1.6.0-10.el7.x86_64.rpm
$ rpm -qpd /var/cache/yum/x86_64/7/base/packages/tree-1.6.0-10.el7.x86_64.rpm