≡ Menu

How to extract a .deb file without opening it on Debian or Ubuntu Linux

I downloaded a .deb Debian file. How do I extract deb package without installing it on my Debian or Ubuntu Linux based system? How do I list and extract the contents of a Debian package?

A Debian or Ubuntu .deb package is nothing but old good Unix ar archive format. The ar command is used to keep together groups of files as a single archive and .deb includes the following three files:

  • debian-binary – A text file indicating the version of the .deb package format.
  • control.tar.gz – A compressed file and it contains md5sums and control directory for building package.
  • data.tar.xz – A compressed file and it contains all the files to be installed on your system.

Let us see how to list and extract the contents of a .deb package file on Debian/Mint/Ubuntu Linux using various command line options.

Related: How To: Extract an RPM Package Files Without Installing It On RHEL/CentOS/Fedora Linux

Step 1 – Download .deb package

Use the apt-get command/apt command as follows to download a file named nginx*.deb:
$ apt download nginx
OR
$ aptitude download nginx
OR
$ apt-get download nginx
Sample outputs:

Get:1 http://in.archive.ubuntu.com/ubuntu xenial-updates/main amd64 nginx all 1.10.0-0ubuntu0.16.04.4 [3,498 B]
Fetched 3,498 B in 0s (4,460 B/s)


To list file use the ls command:
$ ls *.deb
nginx_1.10.0-0ubuntu0.16.04.4_all.deb

Step 2 – Extract .deb package using ar command

The syntax is:
ar x {file.deb}

Install ar command

You can install ar command using the following apt-get command/apt command:
$ sudo apt install binutils
OR
$ sudo apt-get install binutils
Sample outputs:

Reading package lists... Done
Building dependency tree       
Reading state information... Done
Suggested packages:
  binutils-doc
The following NEW packages will be installed:
  binutils
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
Need to get 2,310 kB of archives.
After this operation, 13.6 MB of additional disk space will be used.
Get:1 http://in.archive.ubuntu.com/ubuntu xenial-updates/main amd64 binutils amd64 2.26.1-1ubuntu1~16.04.3 [2,310 kB]
Fetched 2,310 kB in 6s (343 kB/s)                                                                                                                                           
Selecting previously unselected package binutils.
(Reading database ... 92869 files and directories currently installed.)
Preparing to unpack .../binutils_2.26.1-1ubuntu1~16.04.3_amd64.deb ...
Unpacking binutils (2.26.1-1ubuntu1~16.04.3) ...
Processing triggers for libc-bin (2.23-0ubuntu5) ...
Processing triggers for man-db (2.7.5-1) ...
Setting up binutils (2.26.1-1ubuntu1~16.04.3) ...
Processing triggers for libc-bin (2.23-0ubuntu5) ...


To extract nginx_1.10.0-0ubuntu0.16.04.4_all.deb, run:
$ ar vx nginx_1.10.0-0ubuntu0.16.04.4_all.deb
$ ls -l

Sample outputs:

Fig.01: How to extract deb package

Fig.01: How to extract deb package

Extract files from control.tar.gz and data.tar.gz

Type the following tar command:
$ tar xvf control.tar.gz
$ tar data.tar.gz
$ ls -l

All files are extracted into the current directory.

Say hello to dpkg-deb command

You can use the dpkg-deb command to extract .deb file too. The syntax is:
$ dpkg-deb -xv {file.deb} {/path/to/where/extract}
To extract htop_2.0.1-1ubuntu1_amd64.deb in the /tmp/ directory run:
$ dpkg-deb -xv htop_2.0.1-1ubuntu1_amd64.deb /tmp/
To extract htop_2.0.1-1ubuntu1_amd64.deb in the current directory run:
$ dpkg-deb -xv htop_2.0.1-1ubuntu1_amd64.deb .
Sample session:

Fig.02: To extract files from a Debian package use dpkg-deb command

Fig.02: To extract files from a Debian package use dpkg-deb command

How do I view contents of a Debian package without extracting it?

The syntax is:
$ dpkg -c {file.deb}
OR
$ apt-file list {packageName}
For example to view contents of a Debian package named htop_2.0.1-1ubuntu1_amd64.deb, run:
$ dpkg -c htop_2.0.1-1ubuntu1_amd64.deb
Sample outputs:

Fig.03: View contents of a Debian or Ubuntu Linux .deb package using dpkg command

Fig.03: View contents of a Debian or Ubuntu Linux .deb package using dpkg command

You can also use apt-file command as follows

The apt-file is not installed by default. So install it and use it as follows:
$ sudo apt-get install apt-file ## install ##
$ sudo apt-file update ## update package cache ##
$ apt-file list htop ## list htop package contents ##

Sample outputs:

Fig.04: Using apt-file to view the contents of debian packages

Fig.04: Using apt-file to view the contents of debian packages

Share this tutorial on:

Your support makes a big difference:
I have a small favor to ask. More people are reading the nixCraft. Many of you block advertising which is your right, and advertising revenues are not sufficient to cover my operating costs. So you can see why I need to ask for your help. The nixCraft, takes a lot of my time and hard work to produce. If you use nixCraft, who likes it, helps me with donations:
Become a Supporter →    Make a contribution via Paypal/Bitcoin →   

Don't Miss Any Linux and Unix Tips

Get nixCraft in your inbox. It's free:



{ 0 comments… add one }

Leave a Comment

You can use these HTML tags and attributes: <strong> <em> <pre> <code> <a href="" title="">


   Tagged with: