debian-logo-555x242

This short tutorial helps you to create a Debian package from a source tarball. It presumes that you’re using a Debian-derived distribution such as Ubuntu, although it should work with most distributions. It also presumes that you have some prior experience of building a package from the source code.

For most users, the preferred method of adding software to a Linux system is by using a package manager. Package management is very reliable these days, and apart from anything else, it offers an advantage that Linux systems enjoy. However, what do you do when a package that you need isn’t in the repository of your chosen distribution, or it is in there but it’s an old version? In such cases, there is often nothing else for it but to build from source.

Building from source is a reasonably simple process, but it brings with it a few problems. For a start, you’re circumventing the package manager, and this puts its internal database out of sync with the software installed on your computer. You can even end up with two versions of an application installed simultaneously which can cause all sorts of problems.

Thankfully, there is a tool called Checkinstall that is designed to sort out this mess. Checkinstall takes a compiled source code tarball and turns it into a Debian, Slackware or RPM package that you can install “officially” via the package management tools. Furthermore, you can distribute the finished package so that other people can install it without having to build from the source code. Best of all, it’s very easy to use if you already know how to build packages from the source. Checkinstall is not included by default in some distributions, so you might have to search for it and install it via the package manager.

Let’s begin the process of building a package from source:

Prerequisites

To install checkinstall, use the following command:

Package Creation

To keep all complexity behind, I’ll use something which I already have, like the wireshark source code to install a wireshark package. You can start by downloading the source and untar it. Enter the source folder, set appropriate flags if you like and start the configuration script and pass your desired options:

Once that is finished, run the make script

Now don’t run make install, since we don’t want to install it directly, but create package. Instead of running make install, we’ll use checkinstall to create package.

I’ve passed the –install=no and –review-control options. This way, checkinstall won’t install the software and only create a package. The –review-control option can be used to review and alter the package control file.

During the packaging process, checkinstall will ask you several questions regarding the most basic fields. You can fill those in but the –review-control option gives you the possibility to fix possible mistakes. A basic control file can look like this:

Screenshot-from-2015-12-24-122420

If you merely want to build a package to add to your own system, you can safely accept the default answers. However, if you intend to distribute the finished package, it’s a good idea to fill in some of the fields such as your contact details and any other important notes.

Useful Commands

After your package is created, you can add it to your own repository or install it directly by using dpkg. Keep in mind that dpkg won’t install any dependencies.

Sources

Thanks for reading and spending a good time with me to learn something new. For more updates subscribe here. Your comments and feedback are always welcome.