Home » Questions » Computers [ Ask a new question ]

How do you track which packages were installed on Ubuntu (Linux)?

How do you track which packages were installed on Ubuntu (Linux)?

(This question is very similar to 10458. It was suggested that Fedora and Ubuntu/Debian are different enough to warrant different answers.)

Asked by: Guest | Views: 173
Total answers/comments: 5
bert [Entry]

"On any Debian based machine, this is one common way to duplicate a package set. On the old machine:

dpkg --get-selections ""*"" > my_favorite_packages

Copy the file my_favorite_packages to the new machine (a thumb drive is a good option, but scp also works fine). Then run this sequence (with root privileges):

apt-get update
dpkg --set-selections < my_favorite_packages
apt-get -u dselect-upgrade

This doesn't get you only the packages you installed. It also gets their dependencies, etc. Also, if the repositories between the two machines are different, all bets are off.

As far as logs, apt-get keeps a log at /var/log/apt/history.log (thanks to Tshepang for updating this in a comment); dpkg does (at /var/log/dpkg.log), but it's famously hard to parse and can only be read with root privileges; aptitude has one at /var/log/aptitude and you can page through it with regular user privileges.

As far as I can tell, you are right that none of these logs track specifically what you installed as opposed to auto-installed dependencies. You can get that information, however, from an aptitude search. Search for all installed packages that were also installed automatically:

aptitude search '~i ~M'

If you want only the ones you installed (not the auto-dependencies), negate the ~M:

aptitude search '~i !~M'

If you want that formatted so that you have only the names of packages and the word ""install"", aptitude can do that too. This gives you a list ready to feed to dpkg --get-selections:

aptitude search '~i !~M' -F ""%p install""

(I've got nothing on RedHat or RedHat-based systems. Sorry. There really is no one answer for Linux per se since package management is a big part of what makes different distros different.)"
bert [Entry]

"Aptitude is actually quite good at this. Aptitude does know when something was installed by hand or by dependency and you can tell it to remove things that are no longer needed and were only installed because something else depended on it always keeping up your system as small as possible.

There's a handful of packages that make up an Ubuntu installation, ubuntu-minimal, ubuntu-desktop, ubuntu-server and so on. If you tell Aptitude to mark those as manually installed and remove everything else, then you end up with the minimum amount possible of packages.

I explain how to do all that in two posts at my blog: Cleaning up a Debian GNU/Linux and Cleaning up a Debian GNU/Linux (or Ubuntu), reprise. In short, the answer you are looking for is:

aptitude search ~i | grep -v ""i A""

The last time I worked with that, if you used apt-get, then it didn't work. That's why I always recommend aptitude and as far as I know, Debian is deprecating apt-get in favor of aptitude.

I don't know how to do it on Fedora and you should probably separate than into a different question. Fedora and Ubuntu are different operating systems and should be treated as such (even if they share their kernel and some other stuff)."
bert [Entry]

"From man aptitude-create-state-bundle:

aptitude-create-state-bundle produces a compressed archive
storing the files that are required
to replicate the current package archive state.

This will retain the same information that aptitude has on which packages were manually installed.

It's meant to be used with aptitude-run-state-bundle:

aptitude-run-state-bundle unpacks the given aptitude state bundle
created by aptitude-create-state-bundle(1) to a temporary directory,
invokes on it with the supplied ,
and removes the temporary directory afterwards."
"From man aptitude-create-state-bundle:

aptitude-create-state-bundle produces a compressed archive
storing the files that are required
to replicate the current package archive state.

This will retain the same information that aptitude has on which packages were manually installed.

It's meant to be used with aptitude-run-state-bundle:

aptitude-run-state-bundle unpacks the given aptitude state bundle
created by aptitude-create-state-bundle(1) to a temporary directory,
invokes on it with the supplied ,
and removes the temporary directory afterwards."
bert [Entry]

"When just using dpkg you don't know whether the package was manually installed by the user or automatically (as a dependency or during the initial OS install). If you want to retain that information, you need to get a list of only the packages that were actually manually installed.

For that, you can use either of these two one-liners. Both yield the exact same output on my machine and are more precise than all solutions proposed up until now in this question. They are a combination of the two answers (1) and (2). Note that I originally posted this answer here.

Using apt-mark:

comm -23 <(apt-mark showmanual | sort -u) <(gzip -dc /var/log/installer/initial-status.gz | sed -n 's/^Package: //p' | sort -u)

Using aptitude:

comm -23 <(aptitude search '~i !~M' -F '%p' | sed ""s/ *$//"" | sort -u) <(gzip -dc /var/log/installer/initial-status.gz | sed -n 's/^Package: //p' | sort -u)

Very few packages still fall through the cracks, although I suspect these are actually installed by the user, either right after the installation through the language localization setup or e.g. through the Totem codec installer. Also, the linux-header versions also seem to accumulate, even though I've only installed the non version-specific metapackage. Examples:

libreoffice-help-en-gb
openofficedotorg-hyphenation
gstreamer0.10-fluendo-mp3
linux-headers-3.13.0-29

How does it work

Get the list of manually installed packages. For aptitude, the additional sed strips out remaining whitespace at the end of the line.
Get the list of packages installed right after a fresh install.
Compare the files, only output the lines in file 1 that are not present in file 2.

Other possibilities don't work as well:

Using the ubuntu-14.04-desktop-amd64.manifest file (here for Ubuntu 14.04) instead of /var/log/installer/initial-status.gz. More packages are shown as manually installed even though they are not.
Using apt-mark showauto instead of /var/log/installer/initial-status.gz. apt-mark for example doesn't include the xserver-xorg package, while the other file does.

Both list more packages than the above solution."
bert [Entry]

"I am biased, and the solution I present is not always possible, but I got tired of this situation. The result is that I don't install anything anymore with the update/package manager tools.

I took a quite hard route though (I had strict requirements for versions). I created a huge makefile which downloads, compiles and install in my home directory every package (program, library, whatever) I need. I developed it stepwise, piece by piece. The makefile downloads and compiles everything, even the compilers.

When I move to a new system, or reinstall, I just copy the makefile (plus some supporting stuff), run make world and come back the next day.

For some programs I develop (so I have control on), I use a tool I programmed, chestnut package manager. Sort of like .app folders on MacOSX. Everything is in the package, so I know what is installed at any time, and I know it's self contained and self sufficient (except for system libs)"