Skip to main content

Rebuild a DEB Package

·247 words·2 mins
System-Administration Linux Packaging Deb Debian Ubuntu
Table of Contents


Install the required tools by aquiring:

$ apt install build-essential fakeroot dpkg-dev

Get source package

DEB source packages are made up of three files the .dsc which describes the package, the .debian.tar.gz, and .orig.tar.gz. Usually any package found in a distribution will also have the source package files available.

From package manager

Ensure the ‘deb-src’ repositories are enabled, by adding the deb-src locations to the /etc/apt/sources.list and /etc/apt/sources.list.d/* files:

deb focal-updates main restricted
deb-src focal-updates main restricted


Get the source code package and any dependencies needed to build it:

# Get the source of 'package'
$ apt source package

From online

For example, on Debian, the meson binary package found here:

also has a source package files found nearby:

Extract source package

Unpack the package contents from the downloaded file:

$ dpkg-source -x package_<version>-<revision>.dsc

This will extract the content into a folder in the working directory with a name like package-0.0.0/ which will have everything necessary.

Get build dependencies for the package

Navigate to the source directory, such as package-0.0.0/ and:

apt build-dep .

Build the package

If the only thing to do is to build a package as it already is, is to navigate into the source directory, such as package-0.0.0/ and:

$ dpkg-buildpackage -rfakeroot

This will build both the binary and source package.

To build just the binary, use the -b argument, or for just the source package files, -S.