How to Extract Files from a DEB Package on Debian

How to Extract Files from a DEB Package on Debian

Wondering how to extract files from a DEB package on Debian?

Then you’re not alone.

This comprehensive guide will walk you through a step-by-step process to efficiently and accurately extract files from DEB packages on Debian. 

Let’s jump right in!

Understanding Debian Packages

Debian packages can be categorized into two primary types: 1) binary packages and 2) source packages.

The Debian system’s binary packages comprise compiled software, libraries, or executable files. On the other hand, source packages include the software’s source code, which must be compiled for usage.

Both the ar and dpkg-deb commands can be used to extract both packages. These commands come built-in with Debian systems, making interaction with DEB packages simple.

A typical .DEB package consists of the following:

  • debian-binary – It is a text file containing all the information about the version number of the .deb package format. 
  • control.tar.gz – This compressed file comprises the package’s name, version number, and information on what needs to be installed to function properly are provided. Alongside scripts, it also comes with the (md5sums) file, which is used for verifying the integrity of the package’s contents.
  • data.tar.xz – It is also a compressed file featuring all the items the package needs to function on your system. When you install the package, the compressed file items are unpacked, and installation is carried out. The compression used varies according to the package and the type of installation.

What Is the Need to Extract .deb Packages on Debian?

Sometimes you need to extract files from a DEB package when using Debian-based systems. There are several reasons behind extracting the .deb packages, even if it seems like a niche requirement. 

Here are a few scenarios of why it is needed:

  • Extracting helps you inspect the package controls.
  • Extracting the DEB package lets you examine the code.
  • Extracting the DEB package allows you to install its contents manually.
  • Extracting the DEB package helps you modify existing or create a new DEB package.

The ability to extract DEB packages is a skill worth acquiring as you can troubleshoot, create, inspect, or modify packages on Debian easily. 

Continue reading to learn about the prerequisites needed to extract DEB package on Debian, along with detailed steps on how to achieve it.

What You’ll Need

Before we proceed with learning how to extract the .deb packages on Debian, ensure you have the following prerequisites:

  • A running and Debian system (The latest version is preferred)
  • Have a reliable internet connection to download packages or utilities.
  • Ensure you have a basic understanding of command-line usage (guide).
  • For installing utilities, ensure you can access the ‘sudo’ (guide) or root privileges.

If you have all the above requirements, continue reading and learn how to extract the DEB packages on Debian by following the steps below.

How to Extract Files from a DEB Package on Debian: Step-by-Step

Step 1: Update Your Debian System

It is always considered a best practice to update the Debian system before proceeding with any new operation or installation. This is because it updates the local package list on the system and creates uninterrupted and seamless progress.

  1. The below command is responsible for updating the Debian repositories, and it works by retrieving the latest information about available software packages from the Debian repositories. Once retrieved, it ensures the system is up-to-date by fetching updates from different repositories. With that said, enter the command below (you should see the output as shown in the screenshot):
sudo apt update
Extract Files from a DEB Package on Debian 1

Step 2: Download the .deb Package

If you can access a .deb package, then consider this step as a reference. 

  1. For the purposes of this guide and to explain the extraction process, we will be downloading a sample .deb package. However, take note of the command carefully, as it helps you download any .deb packages in the future. The command is shown as follows:
  1. As shown in the screenshot below, the dpkg_1.19.0.5+b1_amd.deb package is downloaded using the free non-interactive file downloader command, wget. This command works by analyzing and resolving the hostname provided to its IP. Once the connection has been established, it sends the HTTP request to download the specified file.
Extract Files from a DEB Package on Debian 2

Step 3: Extract the .deb Package Using the ar Command

Debian uses the ar command extensively to create, modify and extract the files from the archives. It is a part of the binutils package, and if you’re running the latest version of Debian, it comes preinstalled.

However, you might find it missing if you have an older version of Debian or an improperly installed Debian. In such cases, it is mandatory to install it. 

  1. Here is the command to install the binutils package:
sudo apt install binutils
Extract Files from a DEB Package on Debian 3
  1. The installation procedure will start at this point, and you’ll need to confirm it by entering “Y” when requested.
  2. Once you have successfully installed ar on Debian, extract the previously downloaded .deb package using the following command:
ar vx dpkg_1.19.0.5+b1_amd64.deb
How to Extract Files from a DEB Package on Debian
  1. With this command, the .deb package gets extracted, and its files are created in the current directory. To verify whether extraction is done successfully, use the ls command to view the contents of the current directory.
Extract Files from a DEB Package on Debian 4

Step 4: Extract the .deb Package Using the dpkg-deb Command

When working with Debian package files, the dpkg-deb command offers a higher-level interface and more features than the ar command. If you’re looking for extensive metadata and compression capabilities, opt for dpkg-deb over ar.

  1. The syntax of the dpkg-deb is as follows:
dpkg-deb -xv {file.deb} {/path/to/where/extract}
  1. Here is the command in action, where we use dpkg-deb to extract the sample .deb file downloaded before:
dpkg-deb -xv dpkg_1.19.0.5+b1_amd64.deb extracted/
Extract Files from a DEB Package on Debian 5
  1. After running the dpkg-deb command, the contents of the “dpkg_1.19.0.5+b1_amd64.deb” package are extracted into the “extracted” directory.

Since we have already learned how to view the directory’s contents using the ls command in the previous step, we can look into another approach where you can view the directory’s contents. This will be the tree command as shown below:

tree {path_where_extracted}
Command in action: $ tree extracted/
Extract Files from a DEB Package on Debian 6

Also read: How to Reconfigure Installed Packages on Debian 11

[Optional] How to View the Contents of a Debian Package Without Extracting It?

Extracting the package to view its contents would be a waste of time, effort, and resources. For this purpose, the dpkg command allows viewing the contents without extracting the package.

Here is the command to view .deb package files without extracting:

dpkg -c {file.deb}
Command in action: dpkg –c dpkg_1.19.0.5+b1_amd64.deb
Extract Files from a DEB Package on Debian 7


The ar and dpkg-deb commands make the extraction process easy as they are single-line commands. If you don’t understand any command or have difficulty extracting a package, you can refer to  the documentation using the following man commands:

$ man ar
$ man dpkg
$ man dpkg-deb
$ dpkg --help

If you continue to fail with the extraction, share your problem in the Debian community forums or let us know down below in the comments.

Related Posts