Find all manually installed packages within ubuntu

This article shows hot to extract a list of manually installed packges from Ubuntu

1 Min. Lesezeit

The Problem

If you plan to migrate your Ubuntu machine from one hardware to another then you can follow the following approach:

  1. Perform a complete backup your home directory
  2. Extract the list of manually installed packages
  3. Set up a new vanilla Ubuntu on the same or another hardware
  4. Restore the contents of your home directory
  5. Re-install all missing packages

Now - where is the problem ? … If you don’t have a list of your previously installed packages, then it is not possible to use the new box as you have used the old ones - just because some of the programs that you are used to are missing.

The Solution

The solution is (as outlined above) to have a list of packages which were installed on the old computer. Forunately it is a one-liner to get this list:

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

This code snippet works by fetching the list of manually installed packages by getting a list of packages installed right after a fresh install. Afterwards, this list is compared to the list of currently installed packages. The difference between these lists is the manually installed packages.