Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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:

Desired=Unknown/Install/Remove/Purge/Hold
| 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:

Desired=Unknown/Install/Remove/Purge/Hold
| 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?

share|improve this question

4 Answers 4

up vote 19 down vote accepted
dpkg -s <packagename> | grep 'Version'

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

Sample output:

Version: 0.8.1+git.20100810t184654.ab580f4-0ubuntu2
share|improve this answer

It's not using the dpkg command but apt-show-versions Install apt-show-versions is easy.

Example:

$ apt-show-versions network-manager  
network-manager/maverick uptodate 0.8.1+git.20100810t184654.ab580f4-0ubuntu2
share|improve this answer

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 
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-
0.8.1+git.20100810t184654.ab580f4-0ubuntu2
share|improve this answer

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

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

Example:

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

Explanation:

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
Desired=Unknown/Install/Remove/Purge/Hold
| 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 number 2 represents the pacakge name, column 3 represents the Package Version, column 4 represents Architecture and the column 5 represents package description.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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