How to list manually installed packages?
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 (July 6, 2014) in this question.
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
openoffice.org-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.
I used various other StackExchange posts as references, however none work as well as the above solution:
- aptitude + manifest
- initial-status.gz + apt-mark showauto
Both list more packages than the above solution.
EDIT: What to do if you've upgraded from a previous release:
If you've upgraded Ubuntu from one release to the next, you will probably need to adjust this process. In that case, I would check the manifest file of the newer release (see above) in addition to the initial-status.gz file from the current release. You can easily do that by just adding another comparison. Using just the manifest file will not work, as the manifest file unfortunately does not contain everything that the initial_status.gz file does (I checked).
In newer versions of the package apt, there is also the apt-mark command
apt-mark showmanual
For Ubuntu 16.04, check out the log file /var/log/apt/history.log
.
For example:
zgrep 'Commandline: apt' /var/log/apt/history.log /var/log/apt/history.log.*.gz
It's not perfect, but it's pretty good at making it clear exactly what I installed by hand. Put a -B 1
on the grep to see when it was installed.
Example output
Commandline: apt install postgresql-9.5-plv8
Commandline: aptdaemon role='role-install-file' sender=':1.85'
Commandline: apt install task
Commandline: apt autoremove
Commandline: apt install atom
Commandline: apt upgrade
Commandline: apt-get install asciinema
Commandline: apt install iperf3
Commandline: apt upgrade
Commandline: apt-get install chromium-browser
Commandline: apt install joe cpanminus build-essential postgresql libdbd-pg-perl libcrypt-openssl-bignum-perl libcrypt-openssl-rsa-perl libio-socket-ssl-perl libnet-ssleay-perl libssl-dev
Commandline: aptdaemon role='role-commit-packages' sender=':1.2314'
Commandline: apt install git
Commandline: apt install sqlite
Commandline: apt install whois
Commandline: apt install libdbd-pg-perl
Commandline: apt install perl-doc
Commandline: apt upgrade
Not sure if this picks up aptitude
or not. It doesn't seem to pick up installs from the Ubuntu Software desktop app.
apt-mark showauto | grep -iE '^foobar$'
will output "foobar" if the package was installed automatically, nothing otherwise.
aptitude search '!~M ~i'
will list the packages that were not installed automatically. It's a pity aptitude won't be part of the default install on Ubuntu Desktop starting from 10.10.
To get a list of all packages (not installed, installed by user or installed by default, across all PPAs), apt
employs the following method:
apt list [option]
The possible options useful for this are:
--installed
to display only the packages that are installed on the system (out of some 50,000+)
--manual-installed
to list the packages that were explicitly installed by a command, either directly, or as dependencies.
Alternatively, you could do:
apt list --installed | grep -F \[installed\]
to get a list of packages that resulted from user commands and their dependencies only, and to get additional information on them such as version and architecture supported (x86, x86_64, amd64, all, etc.)