29

I would like to list all the installed packages, with specific version numbers on my system. I checked out dpkg --get-selections (How to list all installed packages) but it doesn't show me what I need. For example:

$ dpkg --get-selections apache2
apache2                                         install

shows that apache2 is installed, however not the version. I recently did a apt-get upgrade so apache2.2.22-1 should be version installed (http://packages.ubuntu.com/precise-updates/apache2.2-common), but how can I show that?

Thanks!

user2133697
  • 291
  • 1
  • 3
  • 3

2 Answers2

36

Use dpkg -l instead.

Example:

dpkg -l | grep '^ii' | grep skype

Outputs this:

alaa@aa-lu:~$ dpkg -l | grep '^ii' | grep skype
ii    skype      4.2.0.11-0ubuntu0.12.04.2       i386     client for Skype VOIP...

If you only want to extract the name and version, you can do this:

dpkg -l | grep '^ii' | grep skype | awk '{print $2 "\t" $3}'

Which will only print the second and third column from the above output, like this:

alaa@aa-lu:~$ dpkg -l | grep '^ii' | grep skype | awk '{print $2 "\t" $3}'
skype   4.2.0.11-0ubuntu0.12.04.2

Of course, if you want to list all of your installed packages with their versions, and not only Skype, then just remove the grep skype part to make the command like this:

dpkg -l | grep '^ii' | awk '{print $2 "\t" $3}'
Alaa Ali
  • 31,535
  • I was noticing dpkg -l truncating version numbers if they were longer than 21 characters, and like all package versions are like 22 characters long. :( – ThorSummoner Oct 29 '15 at 22:10
15

Use

dpkg-query --show apache2

to get the version number for package apache2 and

dpkg-query --show 

to get the version numbers for all installed packages

  • 1
    Your solution gave me ~20% more packages than dpkg -l | grep '^ii' | awk '{print $2 "\t" $3}'. Do you know what the difference is? – Thomas Jensen Jun 05 '15 at 19:25
  • 6
    @Thomas Jensen: Thanks for spotting this. dpkg-query --show actually doesn't show the installed packages, but the not not-installed ones. That is it shows e.g. half-installed packages or packages with remaining config files, too. – Florian Diesch Jun 05 '15 at 21:28