This question already has an answer here:

I need to open a Debian deb package file in MacOS High Sierra to compare a binary with one that I have installed in Linux.

Actually the package is mssql-server_14.0.3008.27-1_amd64.deb

The file command says Debian binary package (format 2.0).

tar x and unzip do not work.

What to do?

marked as duplicate by Stephen Kitt debian Feb 12 '18 at 22:40

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.


The outer layer of the actual .deb file is actually an ar archive.

As unpacking/opening it will be generating some files, we would better move it to a directory:

$ mkdir debtmp
$ mv mssql-server_14.0.3008.27-1_amd64.deb 
$ cd debtmp

So as a first step, to unpack it, we do:

$ ar xv mssql-server_14.0.3008.27-1_amd64.deb 
x - debian-binary
x - control.tar.gz
x - data.tar.xz

As for the resulting files, debian-binary just contains the .deb format version:

$ cat debian-binary 

control.tar.gz contains the apt/dpkg info including post/pre/install scripts, dependencies and a checksum file. So we are not actually much interested on it for now.

$ tar -tvf control.tar.gz 
drwxr-xr-x  0 root   root        0 18 Nov 04:55 ./
-rw-r--r--  0 root   root      546 18 Nov 04:55 ./control
-rw-r--r--  0 root   root       25 18 Nov 04:55 ./shlibs
-rwxr-xr-x  0 root   root      383 18 Nov 04:55 ./preinst
-rwxr-xr-x  0 root   root      107 18 Nov 04:55 ./config
-rwxr-xr-x  0 root   root      289 18 Nov 04:55 ./postrm
-rw-r--r--  0 root   root        0 18 Nov 04:54 ./templates
-rwxr-xr-x  0 root   root      251 18 Nov 04:55 ./prerm
-rw-r--r--  0 root   root       60 18 Nov 04:55 ./triggers
-rwxr-xr-x  0 root   root      771 18 Nov 04:55 ./postinst
-rw-r--r--  0 root   root     6155 18 Nov 04:55 ./md5sums

We are then much more interested in the data.tar.zx file, as it contains the configuration files and executable files.

First, we need to install xz, using MacPorts, as tar will need to invoke it, as we are dealing in this .deb file with a .tar.xz.

sudo port install xz

Note: It has been called to my attention in the comments you might also deal with .tar.gz and .tar.gz in other .debs -- however macOS comes with gunzip and bzip2 installed by default.

So, to unpack it:

$ tar xvf data.tar.xz 
x ./
x ./opt/
x ./opt/mssql/
x ./opt/mssql/bin/
x ./opt/mssql/bin/sqlservr
x ./opt/mssql/bin/crash-support-functions.sh
x ./usr/share/doc/mssql-server/license_Std_Linux.txt.gz
x ./usr/share/doc/mssql-server/license_Eval_Linux_Chinese (Simplified).txt.gz
x ./usr/share/doc/mssql-server/license_Std_Linux_French.txt.gz
x ./lib/
x ./lib/systemd/
x ./lib/systemd/system/
x ./lib/systemd/system/mssql-server.service

Finally, having all the files on the local disk, the binary can be fetched from the directory opt/mssql/bin/

Additional notes: As per @AustinHemmelgarn excellent remarks, the last step could also encounter a gzip or bzip2 instead of a xz compression in other .deb files.

  • 1
    It is worth nothing that depending on the vintage of the package, the actual data archive may not be xz compressed (it as originally gzip compressed, and then bzip2, both of which are still supported, and I've heard rumors that the dpkg team may be looking at zstandard support in the near future). – Austin Hemmelgarn Feb 12 '18 at 20:23
  • @AustinHemmelgarn I am focusing on actual packages. Good point, thanks. – Rui F Ribeiro Feb 12 '18 at 20:24
  • 1
    The compression in use doesn’t depend on the .deb version, version 2.0 packages can use gzip etc. too. – Stephen Kitt Feb 12 '18 at 22:43

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