This article hasn't been updated for over 5 years. The information below may be obsolete.

Viewing APT History

Currently the only method of viewing history from the apt-get install command is to review the dpkg logs (/var/log/dpkg.log*) and the apt logs (/var/log/apt/history.log.*.gz)

Whilst this maybe useful, if you don't know what you're looking for it could look like a mess.

To make it easier for me to interegate the logs I wrote a little function to make my life easier :-)

Usage:

apt-history [ install | upgrade | remove | rollback ]

Examples:

  • List which packages installed:
    ubuntu$ apt-history install
    When a specific package installed:
    ubuntu$ apt-history install | grep <pkg-name>
  • Where packages where upgraded or removed:
    ubuntu$ apt-history upgrade
    ubuntu$ apt-history remove
    When a specific package was upgraded/removed:
    ubuntu$ apt-history upgrade | grep <pkg-name>
    ubuntu$ apt-history remove | grep <pkg-name>
  • Which packages have been rolled back:
    ubuntu$ apt-history rollback
    Which specific package has been rolled back:
    ubuntu$ apt-history rollback | grep <pkg-name>

And finally here is my crude function. Yes I could refine it and make it more resilient but it works for me :-)

function apt-history(){

      case "$1" in
        install)
              grep 'install ' /var/log/dpkg.log.1
              grep 'install ' /var/log/dpkg.log
              ;;
        upgrade|remove)
              grep $1 /var/log/dpkg.log.1
              grep $1 /var/log/dpkg.log
              ;;
        rollback)
              grep upgrade /var/log/dpkg.log.1 | \
                  grep "$2" -A10000000 | \
                  grep "$3" -B10000000 | \
                  awk '{print $4"="$5}'
              grep upgrade /var/log/dpkg.log | \
                  grep "$2" -A10000000 | \
                  grep "$3" -B10000000 | \
                  awk '{print $4"="$5}'
              ;;
        *)
              cat /var/log/dpkg.log.
              cat /var/log/dpkg.log
              ;;
      esac
}