How to show the number of installed packages

26,660

Solution 1

According to this thread:

To list installed packages:

dpkg --list | wc --lines

To see if a package is installed:

dpkg --list | grep package

Solution 2

dpkg -l | grep -c '^ii'

There are subtle variants like dpkg -l | grep -c '^?i' if you want to include packages that are installed but whose removal you've requested. Another way is

aptitude search '~i' |wc -l

You can even poke directly into the dpkg database:

sh -c 'set /var/lib/dpkg/info/*; echo $#'

This one includes packages that are not installed but that have configuration files left over; you can list these with dpkg -l | grep '^rc'.

Solution 3

What I've been using is:

dpkg --get-selections | wc --lines

This will give you the number of installed packages.

If you want to find if a particular package is installed, use:

dpkg --get-selections | grep <package>

I believe that this will solve Gilles' complaint about including other, non-installed packages.

Solution 4

dpkg -l is nice but I actually find myself using apt-show-versions (not installed by default on Debian; install the package of the same name) a lot instead, especially when I want to process the output further (dpkg tries to be too clever with line wrapping).

Solution 5

Synaptic, a GUI package manager, displays the count at the bottom of its main window.

enter image description here

Share:
26,660

Related videos on Youtube

tshepang
Author by

tshepang

I do software development for a living and as a hobby. My favorite language is Rust, and I've used Python much in the past. My OS of choice is Debian.

Updated on September 17, 2022

Comments

  • tshepang
    tshepang over 1 year

    What is the Debian equivalent of Fedora's yum list installed | grep wc --lines?

  • Gilles 'SO- stop being evil'
    Gilles 'SO- stop being evil' about 13 years
    You're including the header lines and some non-installed packages (e.g. rc (uninstalled but with config files left over)) in your count.
  • G-Man Says 'Reinstate Monica'
    G-Man Says 'Reinstate Monica' over 7 years
    OK, it's true that nl | tail -1 | awk '{print $1}' will report the number of lines in its input (except, if there is no input, it will say nothing instead of reporting 0) — but why would you recommend such a kludge when other answers are already using wc -l?