7

This question already has an answer here:

Some days ago I downloaded a .deb file that does not have a descriptive name and I want to know which version it is before executing dpkg -i.

I do not know if the same package also comes in a repository, so I am looking to extract this information from the actual file, rather than querying the repository's database.

marked as duplicate by Stephen Kitt, Anthony Geoghegan, G-Man, muru, Romeo Ninov Feb 15 '18 at 7:48

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 1
    In the goal, yes. But that questions are based in verifying a .deb from a repo, not in one that you may have in your file system. Anyway, is a excelent case to know the versions of .deb's. Thank you. – Matias Basso Feb 14 '18 at 15:16
  • The linked question isn’t based on verifying a package from a repository, it’s wide open — it’s only the accepted answer which limits itself to that. The second answer addresses your problem. – Stephen Kitt Feb 14 '18 at 15:38
  • Yes, you are right. I didn't saw it, sorry. Thank you again. – Matias Basso Feb 14 '18 at 16:48
25

To get lots of information about the package use -I or --info:

dpkg-deb -I package.deb
dpkg-deb --info package.deb

To only get the version use, -f or --field:

dpkg-deb -f package.deb Version
dpkg-deb --field package.deb Version
3

The accepted answer is definitely the best way to do it.

If you don't have a deb based system to hand, then it can be helpful to know that a deb file is actually an ar based archive with 3 files in it with almost fixed names. There is debian-binary, a compressed tar file called control which has meta data in it and the main package in a compressed tar file called data. The control.tar.xz file can be extracted, and the control file can be extracted from that and inspected to get the version

$ ar vt zile_2.4.14-6_amd64.deb
rw-r--r-- 0/0      4 Feb 10 11:00 2018 debian-binary
rw-r--r-- 0/0   1372 Feb 10 11:00 2018 control.tar.xz
rw-r--r-- 0/0 170540 Feb 10 11:00 2018 data.tar.xz
$ mkdir /tmp/e ; cd /tmp/e ; ar x ~-/zile_2.4.14-6_amd64.deb
$ xzcat control.tar.xz | tar vtf -
drwxr-xr-x root/root         0 2018-02-10 11:00 ./
-rw-r--r-- root/root       557 2018-02-10 11:00 ./control
-rw-r--r-- root/root       874 2018-02-10 11:00 ./md5sums
-rwxr-xr-x root/root       468 2018-02-10 11:00 ./postinst
-rwxr-xr-x root/root       167 2018-02-10 11:00 ./postrm
-rwxr-xr-x root/root       219 2018-02-10 11:00 ./prerm
$ xzcat control.tar.xz | tar xf -
$ grep Version control
Version: 2.4.14-6
$
  • 1
    (On older debs they may be .tar.gz files rather than xzipped). – hobbs Feb 15 '18 at 4:29
  • 1
    Even recent debs can have gzipped data tarballs; e.g. current linux-source packages are shipped using gzip compression. – Stephen Kitt Feb 15 '18 at 14:50

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