RPM:Tricks

From Vermont Area Group of Unix Enthusiasts

This is an unorganized list of suggestions for working with RPM packages, that aren't included in a typical tutorial or manual.

More can also be found at

Contents

Recent changes

Here's a way to list the 20 most recently installed packages, with their install dates.

 $ rpm -qa --queryformat '%{installtime:day} - %{name}\n' \
   | tail -n 20 | tac
 Mon 21 Apr 2008 - python-devel
 Mon 21 Apr 2008 - openldap-clients
 Thu 17 Apr 2008 - php-manual-en
 Tue 15 Apr 2008 - vorbis-tools
 Tue 15 Apr 2008 - libao
 Tue 15 Apr 2008 - openoffice.org-impress
 Tue 15 Apr 2008 - openoffice.org-calc
 Tue 15 Apr 2008 - thunderbird
 Tue 15 Apr 2008 - openoffice.org-writer
 Tue 15 Apr 2008 - openoffice.org-math
 Tue 15 Apr 2008 - libwpd
 Tue 15 Apr 2008 - a2ps
 Tue 15 Apr 2008 - groff-perl
 Tue 15 Apr 2008 - tetex-latex
 Tue 15 Apr 2008 - texinfo-tex
 Tue 15 Apr 2008 - texinfo
 Tue 15 Apr 2008 - psutils
 Tue 15 Apr 2008 - tetex
 Tue 15 Apr 2008 - tetex-fonts

Package manifest

It's not hard to view the entire list of packages.

 $ rpm -qa 
 libFS-1.0.0-3.1
 xkeyboard-config-0.8-7.fc6
 libXext-1.0.1-2.1
 libdmx-1.0.2-3.1
 rootfiles-8.1-1.1.1
 pam_krb5-2.2.11-1
 chkfontpath-1.10.1-1.1
 xorg-x11-drv-cyrix-1.1.0-4
 distcache-1.4.5-14.1
 evolution-data-server-1.10.3.1-2.fc7
 [...]

That list should be saved to file every so often, and then you can track the changes to a system, using diffutils to see the changes in the list of packages in the file. Unfortunately, diff commands find false positives when a package is updated because the version number changes. List only the names of the packages with this command.

 $ rpm -qa --queryformat '%{name}\n'
 libFS
 xkeyboard-config
 libXext
 libdmx
 rootfiles
 pam_krb5
 chkfontpath
 xorg-x11-drv-cyrix
 distcache
 evolution-data-server
 [...]

Now, the only false positives occur when an application becomes obsolete, or their package name is changed.

Cached version of Yum

Yum seems to always query the repository for every single operation. Really it should use locally cached information to fullfil your requests. It can with the -C option.

 # yum list \*-games
 updates   100% |=========================| 2.3 kB    00:00     
 fedora    100% |=========================| 2.1 kB    00:00     
 Available Packages
 bsd-games.i386             2.17-20.fc7            fedora          
 gnome-games.i386           1:2.18.2.1-3.fc7       updates         
 # yum makecache
 updates               100% |===============| 2.3 kB    00:00     
 fedora                100% |===============| 2.1 kB    00:00     
 other.sqlite.bz2      100% |===============| 7.9 MB    00:51     
 other.sqlite.bz2      100% |===============|  10 MB    01:12     
 Metadata Cache Created
 # yum -C list \*-games
 Available Packages
 bsd-games.i386             2.17-20.fc7            fedora          
 gnome-games.i386           1:2.18.2.1-3.fc7       updates         

Orphan dependencies

I recall that on Debian, when you remove a package, it would also uninstall any unneeded dependencies. I never feel satisfied that RPM is doing that. Fortunately, there is a command that comes with Yum that can show you them.

 $ package-cleanup --leaves
 Setting up yum
 pcsc-lite-libs-1.3.3-1.fc7.i386
 libtermcap-2.0.8-46.1.i386
 libXdamage-1.1.1-1.fc7.i386

Then you can easily remove them, with:

 # yum remove $(package-cleanup --leaves | grep -ve yum)

You can also list all the packages that are not required by any application

 $ package-cleanup --leaves --all
 Setting up yum
 rootfiles-8.1-1.1.1.noarch
 pam_krb5-2.2.11-1.i386
 distcache-1.4.5-14.1.i386
 pydot-0.9.10-5.fc7.noarch
 python-psycopg2-2.0.6-1.fc7.i386
 gnome-applets-2.18.0-7.fc7.i386
 perl-Archive-Tar-1.30-4.fc7.noarch
 nss_ldap-257-4.fc7.i386
 xorg-x11-utils-7.1-4.fc7.i386
 soundtouch-1.3.1-7.fc7.i386
 numactl-0.9.8-2.fc7.i386
 ...

Of course, these are the applications that you need to live, so the requirement is for you to use your computer! So really, you should have a package called "janet" (or your name here), that requires all the things you do on your computer. That way the last command just says -- janet-0.2-2.fc7.noarch.

Recover files for a package

Sometimes you want to restore the configuration files back to their default contents, or perhaps you had some file system problems and want to try and recover a binary file you think is corrupt. You can run yum remove <package> followed by yum remove <package>, but that will be problematic if the file is a dependency for hundreds of packages. There's a way to short circuit this using RPM directly.

If the RPM file is in your local Yum cache, find it and then force the RPM installation:

 # rpm -q krb5-libs
 krb5-libs-1.6.1-9.fc7
 # locate $(!!)
 locate $(rpm -q krb5-libs)
 /var/cache/yum/updates/packages/krb5-libs-1.6.1-9.fc7.i386.rpm
 # rpm -i --force $(!!)
 rpm -i --force $(locate $(rpm -q krb5-libs))

If you have had your Yum cache of RPMs cleaned recently, you can use yumdownloader that comes with the yum-utils package to download the package.

 # yum install yum-utils
 # yumdownloader krb5-libs
 updates                   100% |=====================| 2.3 kB    00:00     
 primary.sqlite.bz2        100% |=====================| 3.1 MB    00:33     
 fedora                    100% |=====================| 2.1 kB    00:00     
 primary.sqlite.bz2        100% |=====================| 3.8 MB    00:49     
 krb5-libs-1.6.1-9.fc7.i38 100% |=====================| 649 kB    00:06     
 # rpm -i --force krb5-libs-1.6.1-9.fc7.i386.rpm

Yum also has a "reinstall" option.

 # yum reinstall krb5-libs

Yum-src

Getting the source RPM (SRPM) of a package can be done with the yumdownloader command.

 $ yumdownloader -source httpd