Skip to main content

Rebuild a DEB Package

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

Preparation
#

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 http://ports.ubuntu.com/ubuntu-ports/ focal-updates main restricted
deb-src http://ports.ubuntu.com/ubuntu-ports/ focal-updates main restricted

 ...etc

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:

https://ftp.debian.org/debian/pool/main/m/meson/meson_0.56.2-1_all.deb

also has a source package files found nearby:

https://ftp.debian.org/debian/pool/main/m/meson/meson_0.56.2-1.debian.tar.xz https://ftp.debian.org/debian/pool/main/m/meson/meson_0.56.2-1.dsc https://ftp.debian.org/debian/pool/main/m/meson/meson_0.56.2.orig.tar.gz

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.