41

Is there any way to get a list of all user-installed packages on an Ubuntu system, i.e. the packages that were installed on top of the default installed packages?

(The idea is to get a comprehensive list that can be used to install the same packages on a clean Ubuntu installation)

Rabarberski
  • 8,492
  • 27
  • 71
  • 87

8 Answers8

18

Look at these files,

  1. '/var/log/installer/initial-status.gz' -- your primary installation
    • this file date would be your installation date (i think)
    • '/var/log/dpkg.log' update timeline (this is what you want)
    • '/var/log/apt/term.log' -- things apt updated on your system
    • '/var/cache/apt/archives/' will contain the deb packages downloaded for installation

Update: use the following two steps for exact list of new installs:

  1. execute: grep -w install /var/log/dpkg.log > full-list.log
  2. Look at lines beyond the /var/log/installer/initial-status.gz timestamp

Since you want to get a clean installation on another system with these packages, you could even copy the 'deb' files from the 'cache/apt/archives' path to that of the new installation and get them installed in one shot (without downloading them again).

nik
  • 55,788
  • 10
  • 98
  • 140
  • Thanks for the tip. It's useful, although I was looking more for a single command to get this list. cat /var/log/dpkg.log | grep 'install ' seems to come close if I ignore the items installed up to the installation date/time – Rabarberski Sep 29 '09 at 11:49
  • Adding a reason for the down-vote would help understand a problem in the answer, if there is one. Would also lead to better answers in future. – nik Oct 04 '09 at 06:25
  • 1
    Oeps, the downvote was accidentally mine. I had already upvoted your answer. When I tried to mark your answer as 'final' I missclicked and hit the down vote arrow. Trying to undo it displayed the message: "Vote too old to be changed, unless this answer is edited." Sorry nik, both for the downvote and the confusion. :-( – Rabarberski Nov 10 '09 at 13:58
  • 1
    @Rabarberski, well that happens... no harm done. – nik Nov 10 '09 at 16:31
  • does not work if /var/log/installer does not exist, like on a server install. Also it would make sense to add VERSION NUMBERS if you are talking about "Ubuntu" - which Ubuntu? –  Oct 02 '11 at 13:18
  • The following command takes archived log files into account as well (such as `/var/log/dpkg.log.1`). The `-h` switch supresses printing of the filename. `grep -wh "install" /var/log/dpkh.log* | sort` – Rabarberski Jul 04 '13 at 12:28
11

Just for grins, I put together a one-liner (here split for clarity) that figures out packages manually installed, excluding those installed initially and any packages automatically installed:

comm -13 \
  <(gzip -dc /var/log/installer/initial-status.gz | sed -n 's/^Package: //p' | sort) \
  <(comm -23 \
    <(dpkg-query -W -f='${Package}\n' | sed 1d | sort) \
    <(apt-mark showauto | sort) \
  )

This works both in bash and in zsh.

PePa
  • 7
  • 2
geekosaur
  • 11,723
  • 32
  • 40
  • This works almost perfectly, except it seems to print out a bunch of libraries installed during the initial install. There's a bunch of `libtiff`, `libxcb`, etc which I didn't install myself. This answer: http://superuser.com/a/105000/24349 takes care of that by sorting according to install time and removing everything before the system install time. Great (ab)use of shell! – haxney Feb 23 '12 at 20:12
4

Based on the information above, I wrote a short Python script to list packages that were manually installed. See this link.

Feel free to use it although I assume no responsibility for it. However, feedback and suggestions are always welcome.

Kazark
  • 3,419
  • 3
  • 26
  • 35
  • Brilliant! It takes a while to run, but it's the only solution I've found which does exactly what I need! – haxney Feb 23 '12 at 20:05
  • 3
    Unfortunately the link is now broken (shows a python traceback) which demonstrates the value of putting the answer here (especially for a "short python script" – David Ljung Madison Stellar Mar 05 '15 at 10:45
  • Found a github repo with the script: https://github.com/gerjantd/bin/blob/master/list-manually-installed-packages/list_manually_installed_packages.py Click on 'raw' to download, and run with 'python list_manually_installed_packages.py' – David Ljung Madison Stellar Mar 05 '15 at 10:59
  • 3
    The github link is now broken, too... – Suzana Dec 11 '15 at 14:21
2

Check my answer here to a related question: How can I display the list of all packages installed on my Debian system?. Some of the other answers on the question also contain nice suggestions on getting such a list.

This question should be marked a duplicate since the earlier question also covers this question, but it might be useful to have this question stand on its own so it's easier to find.

1

This is a hack-job, but it completely works.

First, go to http://releases.ubuntu.com/maverick/ (or whatever version of Ubuntu you're using) and grab the *.manifest file that is associated with the version of Ubuntu you're using.

Then, run the following script (replacing <manifest file>, angle brackets and all, with the path to the file you downloaded. You can always append > output to the end to make a file dump.

diff --suppress-common-lines <(sed 's/ .*//' <manifest file>) <(dpkg --get-selections | sed 's/[ \t].*//') | grep '>' | sed 's/[>] //'
jokerdino
  • 2,465
  • 1
  • 23
  • 33
1

Thanks geekosaur, nice code. I used it but it took a while to figure out how to get it working. Here's how I did it in Ubuntu 11.10—it works in the bash terminal:

comm -13 \
  <(gzip -dc /var/log/installer/initial-status.gz | sed -n 's/^Package: //p' | sort) \
  <(comm -23 \
    <(dpkg-query -W -f='${Package}\n' | sed 1d | sort) \
    <(apt-mark showauto | sort) \
  ) > user-installed-packages

Then to add a tab—\t—and install on each line:

sed 's/$/\tinstall/' user-installed-packages >uip

Then on the new machine:

sudo dpkg --set-selections < uip

And to install the packages:

sudo apt-get dselect-upgrade
Kazark
  • 3,419
  • 3
  • 26
  • 35
jrussell88
  • 11
  • 1
1

assuming you have a consistent history and use aptitude:

history | grep -e "^..... aptitude install"

would list only the packages which you installed with aptitude install ... duh

0

Another way to do this is by determining what has been installed based on your "tasks" which determine the base packages to install according to your initial needs.

tasksel --list-tasks

At the very least you'd have server. However, you may choose to have more. For each of those tasks you have installed, you can get a list of packages that are installed the following command does it all in one line (broken down for clarity) for the ones I have chosen in my installation:

(tasksel --task-packages server ; \
 tasksel --task-packages openssh-server ; \
 tasksel --task-packages lamp-server) | sort | uniq

A generic approach to the above would be:

(for a in $( tasksel --list-tasks | grep "^i" | awk '{ print $2 }' ) ; \
 do tasksel --task-packages $a; done) | sort | uniq

Now use apt-cache depends --installed -i --recurse <packagename> | grep -v "^ " to get a list of dependencies used by all the packages defined in the task. This can be done in one line as follows

apt-cache depends --installed -i --recurse \
     $(for a in $( tasksel --list-tasks | \
                   grep "^i" | \
                   awk '{ print $2 }' ) ; \
       do tasksel --task-packages $a; done) | grep -v "^ " | sort | uniq

The following lists all the packages that are installed in your system (not including dependencies).

dpkg --get-selections | grep "[[:space:]]install" | awk '{print $1}'

Now use the comm command to find the ones that are in the second list only (i.e. ignore those that are in both files and just the first file)

comm -13 <(apt-cache depends --installed -i --recurse \
              $(for a in $( tasksel --list-tasks | \
                            grep "^i" | \
                            awk '{ print $2 }' ) ; \
                do tasksel --task-packages $a; done) | grep -v "^ " | sort ) \
         <( dpkg --get-selections | grep "[[:space:]]install" | \
            awk '{print $1}' | sort)
Archimedes Trajano
  • 1,505
  • 1
  • 15
  • 21