I use the dpkg -l command to find out what version of a package I have installed. For example:

dpkg -l network-manager

returns the information on the package:

| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name                      Version                   Description
ii  network-manager           0.8.3~git.20101118t223039 network management framework daemon

As you can see, it returns 0.8.3~git.20101118t223039 which is wrong because it truncates the version (I've picked a long one for the purpose of this question). The way I've solved this in the past is to pass a stupidly long COLUMNS argument to make it expand:

COLUMNS=200 dpkg -l network-manager

which gives me the entire version number, but also a bunch of junk:

| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name                                         Version                                      Description
ii  network-manager                              0.8.3~git.20101118t223039.d60a988-0ubuntu1   network management framework daemon

Now I can see the full version number, which is 0.8.3~git.20101118t223039.d60a988-0ubuntu1.

I get the feeling that this is not the proper way to find the version number of an installed package. This never really was a problem in the past, but with the tacking on of "ubuntu" in the versions and the proliferation of PPAs these strings are getting longer and longer. Is there an easier way?

dpkg -s <packagename> | grep '^Version:'

e. g.:

dpkg -s network-manager | grep '^Version:'

Sample output:

Version: 0.8.1+git.20100810t184654.ab580f4-0ubuntu2
  • dpkg --info package.deb works, though -s didn't – Twisted Pear Jun 28 '17 at 23:32
  • 3
    @Twisted Pear - dpkg --info package.deb operates on package files, dpkg -s <packagename> operates on package names - no file required – lane Jan 5 '18 at 12:15
  • for completeness: dpkg -s sepio.agent | grep -i '^Version' | cut -d' ' -f2 – Veverke Oct 25 '20 at 22:18
dpkg-query --showformat='${Version}' --show python3-lxml
  • 3
    When querying multiple packages I suggest: dpkg-query --showformat='${Package}\t${Version}\n' --show lsb-release coreutils ... – ThorSummoner Dec 30 '15 at 0:10
  • 7
    I like this version, since it is precise (not grep or cut needed). – guettli Aug 31 '16 at 7:54
  • 2
    Almost certainly want to print a newline, otherwise this is "printf"-like behaviour. For example, dpkg-query --showformat='${Version}\n' --show python3-lxml. – Chris Lamb Jan 28 '19 at 21:54

It's not using the dpkg command but apt-show-versions Install banshee


$ apt-show-versions network-manager  
network-manager/maverick uptodate 0.8.1+git.20100810t184654.ab580f4-0ubuntu2

I think aneeshep's is the best answer as your question specifies using dpkg. But for completeness sake, here's another way:

apt-cache policy network-manager 
  Installed: 0.8.1+git.20100810t184654.ab580f4-0ubuntu2
  Candidate: 0.8.1+git.20100810t184654.ab580f4-0ubuntu2
  Version table:
 *** 0.8.1+git.20100810t184654.ab580f4-0ubuntu2 0
        500 http://us.archive.ubuntu.com/ubuntu/ maverick/main i386 Packages
        100 /var/lib/dpkg/status

Or for just the version number:

apt-cache policy network-manager | grep 'Installed:' | cut -c 14-
  • 1
    The output of apt-cache depends on the current Locale. For example in Germany you need to grep 'Installiert:'. To compensate for that, always use Locale C.UTF-8 when scripting. Either with LC_ALL=C.UTF-8; export LC_ALL at the start of the script or for a case-by-case basis something like: LC_ALL=C.UTF-8 apt-cache policy network-manager | grep 'Installed:' | awk '{print $2}' – Tino Feb 14 '18 at 13:09

Another method to find the version of an installed package via dpkg as below,

dpkg -l | awk '$2=="package-name" { print $3 }'  


$ dpkg -l | awk '$2=="network-manager" { print $3 }'


dpkg -l command lists all the installed packages.This standard output was fed as input to the awk command.awk searches for the corresponding package name in the standard input(column 2) if it finds then it grabs the corresponding line. And finally prints the value of (column 3) which was actually represents the package version.

$ dpkg -l
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name           Version      Architecture Description

According to the above, column 2 represents the package name, column 3 represents the package version, column 4 represents the architecture and column 5 represents package description.

  • Why do you need to list all packages using dpkg first and then let awk filter them again? You can request the listing for a single package as well: dpkg -l <package-name> – gertvdijk Jul 31 '18 at 13:56

The command apt -qq list <package-name> shows whether the package is installed and appears to return the full version number.

Example 1 – uses -qq

$ apt -qq list network-manager
network-manager/now 1.10.14-0ubuntu2 amd64 [installed,local]

Example 2 – uses -qq and *

$ apt -qq list virtualbox-6*
virtualbox-6.0/unknown 6.0.24-139119~Ubuntu~bionic amd64
virtualbox-6.1/unknown,now 6.1.16-140961~Ubuntu~bionic amd64 [installed]

Example 3 – uses -qqa

$ apt -qqa list keepassxc
keepassxc/bionic,now 2.6.2-1ppa1~bionic1 amd64 [installed]
keepassxc/bionic 2.3.1+dfsg.1-1 amd64

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.