How to find manually installed packages?

Solution 1:

With this suggestion, I'm assuming your old installation will still boot!

To replicate one set of packages on another machine:

On System A, run:

dpkg --get-selections | grep -v deinstall > my-selections

Move the my-selections file over to System B.

On System B, run:

dpkg --set-selections < my-selections

and then:

sudo apt-get dselect-upgrade

Important note: if you have installed packages from non-standard repositories and/or PPAs, you will also want to copy /etc/apt/sources.list and the contents of /etc/apt/sources.list.d/ from System A to System B before you run the upgrade.

You can use dpkg to see what you've removed as well (NB: this will also include packages that you manually installed and removed):

dpkg --get-selections | grep deinstall

You can see your results in the terminal, or, of course, redirect to a file.

Solution 2:

This thread from superuser.com gives this solution:

aptitude search '?installed ?not(?automatic)'

Solution 3:

If your apt logs are in /var/log/apt, something like this should work:

gunzip -c /var/log/apt/history.log.*.gz | grep "apt-get install"

Or if you want to get rid of some of the repetitive junk in the output:

gunzip -c /var/log/apt/history.log.*.gz | grep "apt-get install" \
  | cut -f4- -d" " | sort | uniq

Solution 4:

You could use apt-mark, but I recommend debfoster:

sudo apt-get install debfoster
sudo debfoster

This will inspect all installed packages and figure out which ones are keeping the others installed:

texlive-full is keeping the following 161 packages installed:
  cm-super cm-super-minimal context doc-base dvipng feynmf
  fonts-gfs-artemisia fonts-gfs-baskerville fonts-gfs-bodoni-classic
  ...
Keep texlive-full? [Ynpsiuqx?], [H]elp:

As you answer "y" to each question (just push Enter to move quickly), debfoster will collect the package list and write them line-by-line to a file. By default this is at /var/lib/debfoster/keepers. It looks like this:

gnome-do
texlive-full
...

I configure debfoster via /etc/debfoster.conf to put this list at /etc/debfoster-keepers and track the file with etckeeper to keep history and backups. The answer here shows how to install a list of packages from a newline-delimited text file:

sudo apt-mark manual $(cat debfoster-keepers)

Note a limitation here, packages you purged have a '-' in front of them. So you want to remove those lines before calling apt-mark.

Even though the debfoster's website says that debfoster is deprecated in favor of aptitude, I prefer debfoster's prompt and simple configuration. It puts you in the middle of your package database and lets you clean things up, making the auto and manual packages more obvious.

Type "h" at the debfoster prompt to explain your options. Type "?" to see the package description. The how-to here might be useful.

Solution 5:

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

Gives all manually installed packages (not system packages, not dependencies). For examples it shows build-essential but not gcc.