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

Idownloaded 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

Tutorial details
Difficulty level Easy
Root privileges Yes
Requirements Linux terminal
Category Package Manager
OS compatibility Debian  Linux  Mint  Pop!_OS  Ubuntu
Est. reading time 4 minutes

Step 1 – Download .deb package for extracting the .deb file

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:




To list file use the ls command:
$ ls *.deb
nginx_1.18.0-0ubuntu1.3_all.deb

Step 2 – Extract .deb package using ar command

The syntax is as follows to extract .deb file on Ubuntu or Debian Linux:
$ ar x {file.deb}

Installing the ar command

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


To extract nginx_1.18.0-0ubuntu1.3_all.deb, run:
$ ar vx nginx_1.18.0-0ubuntu1.3_all.deb
$ ls -l

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 to extract tarball. For example:
$ 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

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 ##

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

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

Summing up

And that is we extract .deb file or view contents of downloaded .deb files on Debian or Ubuntu Linux. For more info see the following man pages documents using the help command or man command:
$ man ar
$ man dpkg
$ man dpkg-deb

Did you find this article useful?