jump to navigation

How to Display the History of Packages that Were Managed via YUM November 7, 2012

Posted by Tournas Dimitrios in Linux.

Yum is great , all you have to do is tell it the name of the program or library and off it goes , installing files all over your computer . Actually , Yum is an application built on top of the rpm API . While rpm doesn’t resolves dependencies during installation of a package ( it just throws a bunch of errors , warning you what extra packages need to be installed prior this package can be installed) , Yum does everything behind the “scenes” . One other benefit of using Yum for installing packages is that it has it’s own “history-database” . Have you ever found yourself hunting all over your computer’s hard drive , trying to find exactly when a package was installed ? Then Yum’s “history” feature is what you really need to master .

Prerequisites : This article will go directly into practical examples (skipping all details ) . The reader should already  be familiar with basic concepts of package management via the terminal (installing , updating , removing , searching) . I won’t even mention what a repository is or how to install extra repositories into your default installation ( this Blog has already published a few articles that introduced these concepts) .

As with pretty much everything on Linux , yum keeps a record of what it does . This record lives in : /var/log/yum.log  . So , you could take a look in this file and see what packages were installed on what date . A sample of this file is shown below .

[ec2-user@aws-server]$ su -
[root@aws-server]# less /var/log/yum.log
Oct 31 16:14:48 Installed: apr-1.3.9-5.el6_2.x86_64
Oct 31 16:14:48 Installed: apr-util-1.3.9-3.el6_0.1.x86_64
Oct 31 16:14:49 Installed: apr-util-ldap-1.3.9-3.el6_0.1.x86_64
Oct 31 16:14:49 Installed: httpd-tools-2.2.15-15.el6.centos.1.x86_64
Oct 31 16:14:49 Installed: mailcap-2.1.31-2.el6.noarch
Oct 31 16:14:51 Installed: httpd-2.2.15-15.el6.centos.1.x86_64
Oct 31 16:15:22 Updated: kernel-firmware-2.6.32-279.11.1.el6.noarch
Oct 31 16:15:22 Updated: 12:dhcp-common-4.1.1-31.0.1.P1.el6.centos.1.x86_64
Oct 31 16:15:25 Updated: selinux-policy-3.7.19-155.el6_3.4.noarch
Oct 31 16:15:28 Updated: tzdata-2012f-1.el6.noarch
Oct 31 16:15:33 Updated: glibc-2.12-1.80.el6_3.5.x86_64
Oct 31 16:15:51 Updated: glibc-common-2.12-1.80.el6_3.5.x86_64
Oct 31 16:15:52 Updated: device-mapper-1.02.74-10.el6_3.2.x86_64
Oct 31 16:15:52 Updated: device-mapper-libs-1.02.74-10.el6_3.2.x86_64
Oct 31 16:15:52 Updated: nspr-4.9.1-2.el6_3.x86_64
Oct 31 16:15:53 Updated: krb5-libs-1.9-33.el6_3.3.x86_64
Oct 31 16:15:53 Updated: nss-util-3.13.5-1.el6_3.x86_64
Oct 31 16:15:53 Updated: nss-3.13.5-1.el6_3.x86_64
Oct 31 16:15:54 Updated: nss-sysinit-3.13.5-1.el6_3.x86_64
Oct 31 16:15:56 Updated: openssl-1.0.0-25.el6_3.1.x86_64
Oct 31 16:15:56 Updated: device-mapper-event-libs-1.02.74-10.el6_3.2.x86_64
Oct 31 16:15:57 Updated: libxml2-2.7.6-8.el6_3.3.x86_64
Oct 31 16:15:57 Updated: python-libs-2.6.6-29.el6_3.3.x86_64

If there isn’t a special reason to install your packages via RPM , I highly recommend you to “stick” with Yum . Over the last years of my experience , I learned that Yum is the most efficient way to handle packages .

Keep in mind though , that /var/log/yum.log is under control of the logrotate utility . Simply put , this utility (logratate) prohibits any log-file from appending new records infinitely , in long term , that would result into unmanageable file sizes . Logrotate periodically creates a new empty log-file (the old log-file is archived as a back-up) .  The time-interval in which this “clean-process” should happen is defined by directives into /etc/logrotate.conf file . Each application that writes records into log-files can further customize logrotate’s  behavior (time-interval , max allowable file-size)  by writing directives into a file  which should be placed into  /etc/logrotate.d/  directory . Yum’s logging directives are defined into /etc/lograted.d/yum  , it defines a max file-size of 30k and a”yearly” time-interval (whichever will occur first) . Here follows an example .

[root@aws-server]# cat /etc/logrotate.d/yum
/var/log/yum.log {
    size 30k
    create 0600 root root

Although you could directly read the log file (it’s just a plain text file)  , Yum itself has a history command , so you can also see this information in a much prettier way by typing : yum history . An example of my fresh CentOs Cloud-instance installation is  :

Other command options  are :

  • yum history  package  xxxxx  :  Where “xxxxx” represents the package name (for example httpd)
  • yum history info xx  : Where “xx” represent the ID , it was assigned to the package during installation (first column in the picture above)
  • yum history  undo  : simply undo operations by history ID.
  • yum history list  : History list after undo
  • yum history  redo  : simply redos operation from yum history by ID
  • yum history new  :  delete/clear old history listing
  •  yum help history  :  a complete list of options (redo , undo , …. )  .

The following example demonstrates how to find information about Apache’s installation history :

[root@aws-server]# yum history package httpd
Loaded plugins: fastestmirror, security
ID     | Action(s)      | Package
     2 | Install        | httpd-2.2.15-15.el6.centos.1.x86_64
history package
[root@aws-server]# yum history info 2
Loaded plugins: fastestmirror, security
Transaction ID : 2
Begin time     : Wed Oct 31 18:14:44 2012
Begin rpmdb    : 450:a6ed9117dc5fb11ecde77064d62a2b115e8e1dcb
End time       :            18:14:52 2012 (8 seconds)
End rpmdb      : 456:297f39d7cfddbc7be0e1ae862fe910dfe8541557
User           : EC2 Default User
Return-Code    : Success
Command Line   : install httpd
Transaction performed with:
    Installed     rpm-4.8.0-27.el6.x86_64                       @CentOS/6.3
    Installed     yum-3.2.29-30.el6.centos.noarch               @CentOS/6.3
    Installed     yum-plugin-fastestmirror-1.1.30-14.el6.noarch @CentOS/6.3
Packages Altered:
    Dep-Install apr-1.3.9-5.el6_2.x86_64                  @updates
    Dep-Install apr-util-1.3.9-3.el6_0.1.x86_64           @base
    Dep-Install apr-util-ldap-1.3.9-3.el6_0.1.x86_64      @base
    Install     httpd-2.2.15-15.el6.centos.1.x86_64       @base
    Dep-Install httpd-tools-2.2.15-15.el6.centos.1.x86_64 @base
    Dep-Install mailcap-2.1.31-2.el6.noarch               @base
history info

Since yum 3.2.26 yum has started storing additional information about installed packages in a location outside of the rpm-database . None of the information stored there is critical to performing its function but it enhances the user experience and makes it possible to know more about the context in which a package was installed . Accessing these extra information is by the yumdb  command  . The man pages are a valuable source for further discovering of this command (yumdb) or this on-line information .

Just for completeness , I would like to demonstrate another way of getting information about a rpm-package that was installed (date) . It uses RPM’s database to parse the results :

[root@aws-server]# rpm -qa --queryformat '%{installtime}(%{installtime:date}) %{name}\n' |sort -n|tail -20
1351700762(Wed 31 Oct 2012 06:26:02 PM EET) php-mysql
1351700762(Wed 31 Oct 2012 06:26:02 PM EET) php-pdo
1351840529(Fri 02 Nov 2012 09:15:29 AM EET) gpg-pubkey
1351842783(Fri 02 Nov 2012 09:53:03 AM EET) epel-release
1351851046(Fri 02 Nov 2012 12:10:46 PM EET) libXmu
1351851047(Fri 02 Nov 2012 12:10:47 PM EET) libXaw
1351851047(Fri 02 Nov 2012 12:10:47 PM EET) libXpm
1351851047(Fri 02 Nov 2012 12:10:47 PM EET) xterm
1351851048(Fri 02 Nov 2012 12:10:48 PM EET) perl-X11-Protocol
1351851049(Fri 02 Nov 2012 12:10:49 PM EET) perl-Tk
1351851050(Fri 02 Nov 2012 12:10:50 PM EET) clusterssh
1352004095(Sun 04 Nov 2012 06:41:35 AM EET) mhash
1352004096(Sun 04 Nov 2012 06:41:36 AM EET) libmcrypt
1352004566(Sun 04 Nov 2012 06:49:26 AM EET) php-mcrypt
1352005674(Sun 04 Nov 2012 07:07:54 AM EET) php-pear
1352005675(Sun 04 Nov 2012 07:07:55 AM EET) php-pear-HTML-Common
1352005676(Sun 04 Nov 2012 07:07:56 AM EET) php-pear-HTML-Table
1352198681(Tue 06 Nov 2012 12:44:41 PM EET) perl-TermReadKey
1352198681(Tue 06 Nov 2012 12:44:41 PM EET) perl-Time-HiRes
1352198682(Tue 06 Nov 2012 12:44:42 PM EET) maatkit
[root@aws-server]# rpm -qa --queryformat '%{name}:\t%{installtime:date}\n' | grep http
httpd-tools:    Wed 31 Oct 2012 06:14:49 PM EET
httpd:  Wed 31 Oct 2012 06:14:50 PM EET

Hope you enjoyed this article .



1. Denis - November 13, 2012

nice post! i have read your article and it is really amazing.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s