What's the most robust way to parse a source package's debian/changelog file (or debian/control?) to get the package's version number? Something like:

pkgver=$(dpkg-parsechangelog | magic_goes_here)

I want to extract the version number (and only the version number) so that I can manipulate it in a script.

I was expecting to find a dpkg-* utility for this purpose, but I haven't found one yet.


4 Answers 4


If you have version 1.17.0 or later, you can use

dpkg-parsechangelog --show-field Version

No need to process the output further then. This version is currently (February 2014) available in Debian Testing.

  • 1
    @RichardHansen: Sorry about that, it turns out that the flag isn't available in the version present in Debian Stable. Feb 21, 2014 at 7:44
  • Same for Ubuntu 12.04. It is present in Ubuntu 14.04 though.
    – Stefan
    Jul 14, 2014 at 15:48

There are numerous ways to do this.

dpkg-parsechangelog | sed -n 's/^Version: //p'

or alternatively:

dpkg-parsechangelog | grep Version: | cut -d' ' -f2-

  • I was hoping for something a bit more robust -- the deb-control(5) man page does not clearly describe the format and I don't want to make any assumptions. For example, it does not make it clear that fields must start on a line ("Fields are delimited only by field tags."). It also says that a field can span multiple lines, and it doesn't say anything about spacing between the tag and the value, so maybe Version:123 should be interpreted as a continuation of the previous field and not a separate Version field (due to the lack of a space after the colon). Aug 15, 2013 at 16:56
  • In practice, the output from dpkg-parsechangelog is going to look like Version: 0.6.11-2 If you want something to do more robust parsing of the debian/control format, you could use python-debian or libparse-debcontrol-perl. Aug 15, 2013 at 18:55

dpkg-parsechangelog works, and the earlier answer piping the output through sed/grep should be entirely robust. If you want to know precise details of the format of dpkg-parsechangelog output, and most other debian-style control files, see RFC 822. It is never ok for a deb package version to contain a newline, space, or any other special or control characters (see man deb-version), so the "Version: blah" line in the output will always be present, and it will always be a single line on its own.

However, dpkg-parsechangelog is a very heavy program to run just to get the current version number from a changelog. It has to run Perl and load an impressively large number of libraries in order to give you a result, most of which you won't use. On slower platforms, or with slow file storage media, or when you need to do this version parsing lots of times, it will prove quite painfully slow. Instead, just use whatever is inside the first set of parentheses on the first line:

head -1 debian/changelog | awk -F'[()]' '{print $2}'

That will get you the correct current package version with any valid changelog file using the standard format (and nonstandard debian/changelog formats are, for all practical general purposes, never used).


as I have seen package version consists at header part of the changelog file. so you can do it like

pkgver=$(dpkg-parsechangelog | head

I have tried this command for installed packages, for example

aptitude changelog shutter | head


jai@frank-Jai:~$ aptitude changelog shutter | head
Get: Changelog of shutter
shutter (0.89.0-0ubuntu1) quantal; urgency=low

  * New upstream release.
   - Adds an AppIndicator (LP: #805464).
  * debian/control: Recommend libgtk2-appindicator-perl

 -- Andrew Starr-Bochicchio <a.starr.b@gmail.com>  Sat, 11 Aug 2012 17:36:18 -0400

shutter (0.88.3-1) unstable; urgency=low
  • 1
    I want the version number and only the version number so that I can manipulate it in a script. Aug 15, 2013 at 4:55

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.