Creating Debian packages with checkinstall

Lately I’ve been working on automating my server infrastructure. One of the tasks at hand was to simplify the way I install certain software.
For instance, for my web-stack, I compile ruby and nginx manually, so I can compile them using specific parameters.

When I started researching this, I got overwhelmed with all different kind of information. Since my packages don’t need to be published on any official repository, I only need minimum configuration. Just enough so I can install them without any problems.

Prerequisites

When I started researching this, I got overwhelmed with all different kind of information. Since my packages don’t need to be published on any official repository, I only need minimum configuration. Just enough so I can install them without any problems.

apt-get install build-essential

When you want to compile software, the build-essential package is, well, like the package name says, essential 🙂 .

Create your package

There are many tools out there that assist you in creating packages. One that I found pretty easy to use was checkinstall.

As the documentation states, checkinstall keeps track of all the files created or modified by your installation script, build a standard binary package and optionally installs it.

To install checkinstall, use aptitude:

$ sudo apt-get install checkinstall

To keep all complexity behind, I’ll use something basic, like the ruby source code to install a basic ruby package.

Package creation

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:

$ ./configure --prefix=/usr/local --enable-pthread --enable-shared --disable-install-doc

Once that is finished, run the make make script

$ make

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.

# checkinstall --install=no --review-control

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:

Package: <package-name>
Version: <package-version>
Architecture: <all|i386|amd_64>
Priority: <required|important|standard|optional|extra>
Maintainer: <maintainer-name> <maintainer-email>
Section: <package-section>
Homepage: <homepage-of-the-software>
Description: <package-description>

See the debian policy for more information on the control file.

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.

# dpkg -i PACKAGE.deb => install package
# dpkg -r PACKAGE-NAME => remove package
# dpkg –purge PACKAGE-NAME => remove all files of package