Creating .deb packages from source

Posted on Fri 23 August 2013 in Linux

This article assumes you are already familiar with how to compile programs from source code.

Now, fortunately Debian provides some great tools for this. Let's begin by installing them:

apt-get install devscripts equivs

There are two programs you'll likely use a lot, mk-build-deps and debuild. The first one figures out the dependencies for compiling the software and creates a .deb package you can install to get those dependencies. The second one compiles and builds a .deb package for the software. Both programs rely on a debian directory containing all kinds of information inside the source code directory. Some source code is shipped with this directory and for others you will have to make your own.

Typical use

Assuming the source code contains a debian directory;

In source code directory, first get build dependencies:

mk-build-deps
dpkg -i package-build-deps...deb
apt-get -f install

Compile the source and build a package:

debuild -uc -us -b -j2

This should put a .deb package in the directory above the source code directory.

-uc means do not sign the .changes file and -us means do not sign the source package. -b is binary-only build.

No debian dir in source?

If there is an older version of the software you are compiling in the official Debian repository you might be able to successfully build the package by taking the debian directory from the source package of the older version and put it in the source of the new version. You'll also have to update the debian/changelog.

apt-get source mpd
cd mpd-version
cp -R debian /path/to/your/new/source/

Then open /path/to/new/source/debian/changelog and copy the most recent entry to the beginning of the file and change version + timestamp, then try "Typical use" above.