56

apt-cache dump --installed doesn't work, it lists uninstalled packages as well.

I want to list the install packages each by one line, with the installed version number.

Lenik
  • 17,942
  • 25
  • 87
  • 119
  • 3
    [bug #775771](https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=775771) restrict apt-cache search results to installed packages – bartolo-otrit Feb 16 '15 at 13:58

7 Answers7

57

try dpkg -l

it lists you the packages, version and a short description.

kev
  • 861
  • 8
  • 5
39

The simplest way is using dpkg, but it might show a few extraneous packages and it truncates long package names and version numbers:

dpkg -l

To list only correctly installed packages and not truncate names:

dpkg -l | grep '^ii'

To get more control over the output format, you can use dpkg-query:

dpkg-query -W -f '${status} ${package} ${version}\n' | \
sed -n 's/^install ok installed //p'
Spooky
  • 428
  • 5
  • 13
Gilles 'SO- stop being evil'
  • 69,786
  • 21
  • 137
  • 178
13

Other command can be:

apt-show-versions

It also gives you info about the package state (up to date, upgradable, ...) and about the origin distribution (wheezy, jessie, ...). One can easily filter out packages which came from backports or other exotic repositories.

This program is packaged separately. Install it first with:

apt-get install apt-show-versions
SkyRaT
  • 494
  • 5
  • 8
  • This is really nice as it shows the version that a package could be upgraded to. +1. – Randall Cook Apr 21 '15 at 17:26
  • combined with `apt-mark showmanual` this gives you a nice and easy way to retrieve versions of all manually installed packages, see also [this Askubuntu answer](https://askubuntu.com/questions/2389/generating-list-of-manually-installed-packages-and-querying-individual-packages/492343#492343) `apt-mark showmanual > /tmp/versions && apt-show-versions | grep -f /tmp/versions` – Gregor Aug 28 '17 at 14:32
5

The following command lists the packages with their versions, and additionally it lets you set up a system with the same packages and versions later, using the pkg-selections.txt file generated here:

aptitude -q -F "%?p=%?V %M" --disable-columns search \~i > pkg-selections.txt

Each line will contain package name, version and an optional "A" if the package was installed automatically.

Source: "Cloning a Debian system - identical packages and versions". Also contains the script that sets up a system from pkg-selections.txt.

tanius
  • 790
  • 1
  • 10
  • 20
4

To list the names of each installed package, type as any user:

dpkg --get-selections

You will get an output like this :

accountsservice              install
aclinstall                   install
acpi-supportinstall          install
acpidinstall                 install
...

To remove the unecessary "install" character string, you can use sed :

dpkg --get-selections | sed 's:install$::'

And if yout want to save it to a file called InstalledPackages, you type this :

dpkg --get-selections | sed 's:install$::' > InstalledPackages
Rémi G.
  • 49
  • 2
2

If you do not have access to live system, and have a backup of root/ partition, you can :

root@backup_server /mnt/old_root/var/lib/dpkg/info # ls -la *.list | awk {'print $9'}| sed 's/.list//' >> /root/installed_app

Now this /root/installed_app contain all installed packages!

sasha2002
  • 29
  • 1
0

For anyone finding this question years later, like I did:

  • With apt you can do apt list --installed for a pretty printed list.
  • dpkg-query -W without any formating options gives you package name and version.
  • sed -En 's/^(Package|Version): //p' /var/lib/dpkg/status | paste - - Will give you the same output as above. This works without debian/ubuntu tools (say Ubuntu rootfs is mounted from RHEL).
micke
  • 3,345
  • 17
  • 25