How to create DEB packages for Debian/Ubuntu

A DEB package is an archive containing all files including compiled version of applications, source codes, configuration files, images and installation commands. DEB files in Debian-based operating systems like Ubuntu and Kali Linux are equivalent to EXE files found in Windows.

Here’s how you can develop your own DEB packages for a Debian-based Linux distribution.


Step 1: Install required packages

Preparing a Debian package requires certain programs. To get started, install these utilities on your system:

sudo apt install build-essential binutils lintian debhelper dh-make devscripts

Step 2: Package selection

Before creating a Debian package (DEB) for a program, you should consider a few things:

Step 3: Start preparing the package

First, create a new directory under your home directory to avoid confusion.

cd /home
mkdir package
cd package

Then extract the tarball containing the source code of the program you are going to package under this directory. For the demonstration, we will use the rsyslog archive.

tar -zxvf rsyslog-6.3.6.tar.gz

Navigate to the newly created directory using the cd command:

cd rsyslog-6.3.6

Usually the source code of the program comes with INSTALL and READ ME files. Even if you know what the program is and how it works, you will benefit from spending some time reading these files.

There are commands such as ./configure do and install which can easily install such archives on your system. But there are several parameters for the ./configure option you should be aware of. You can use the ./configure –help command to get this information.

Step 4: Add developer information

Before creating a DEB package for your program, pay attention to the package name and version number. You will also need to add packager information when creating a package. To do this, you must export your information with the following commands:

export DEBEMAIL=""
export DEBFULLNAME="Name Lastname"

After that use the magic command dh_make.


After issuing the dh_make order, you need to select your package type and press Walk in.

Following this step, you will notice a directory within a parent directory with the “.orig” extension. If that doesn’t work, try running the dh_make order with the –createorig setting.

rsyslog-6.3.6 rsyslog_6.3.6.orig.tar.xz rsyslog-6.3.6.tar.gz

You may also see a new directory named Debian in the current working directory. These directories and files contain all the Debian package information regarding the program.

You should know the following information about the files located in the Debian directory.

1. The control file

The control file offers a variety of package-related information.

  • Source: The line where you will specify the name of your program
  • Section: The line that determines which section your program belongs to according to the license
  • Maintainer: The line containing the information of the person who prepared the package
  • Depends on build: Dependencies are listed on this line
  • Depends: This line is very important. You specify your package dependencies with this value
  • The description: The line where you can enter package information

This file contains program license information. Its default content is as follows:

3. The changelog file

This file is like your program’s logbook roadmap. If you did something independent of the program source or fixed bugs, you can add it to this file.

4. The rules file

The rules file is like a Makefile for your Debian package. When installing the Debian package prepared with dpkg, the information contained in this file is taken as a basis.

You can of course modify the parameters of this file as you see fit.

5. Other files in the directory

It may also be useful to know the functions of the following files:

  • README.Debian: Readme File
  • conffiles.ex: Use this file if you want to keep your old settings file when installing the program
  • cron.d.ex: You can perform cron operations using this file
  • directories: Use this file to specify directories that should not be installed during installation but should be created later
  • documents: If there are documents with your program, specify them with this file
  • emacsen*.ex: If your program needs the Emacs file when installing, specify it with this file
  • init.d.ex: Use this file if you want your program to run at system startup

To move on to the next step, delete any files you think you no longer need. Then rename the file extensions and remove “.ex” at the end. The “.ex” (example) indicates that this is an example file.

Step 6: Build the package

If you have made it this far, you can now prepare the Debian package for your program. To do this, run the following command:


Another big issue here is creating a GPG for the email address you are exporting as a manager.

export DEBEMAIL=""

dpkg will look for your GPG information when building the package. You can list it with the command gpg –list-keys.

If you encounter problems in the dpkg-buildpackage phase, try the following command:

dpkg-buildpackage -nc -i

This command will skip some parts that may cause an error.

If all goes well, the Debian package for your program will be ready to install and stored in the following directory. With the command below you can install, test and review the package.

dpkg -i package-name

Anyone can package on Linux

The DEB packaging system is one of the most fundamental elements that distinguishes Debian as the GNU/Linux leader. Debian is a large system and it is very important that contributors have the ability to create their own packages.

If you’re new to GNU/Linux, this might seem confusing. However, as you can see, preparing a Debian package is easier than you might think. Of course, building a Debian package takes time and work.

But that doesn’t mean you have to manually create packages for the programs you want to install. There are several websites on the internet from which you can download DEB packages for free.

Source link

Steven L. Nielsen