Linux

How to Create DEB Packages for Debian/Ubuntu

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

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

MAKEUSEOF VIDEO OF THE DAY

Step 1: Installation of Required Packages

Preparing a Debian package requires some programs. To begin, 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 points:


Step 3: Begin to Prepare the Package

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

cd /home
mkdir package
cd package

Then extract the tar archive containing the source code of the program you’re going to package under this directory. For demonstration, we’ll 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 README files. Even if you know what the program is and how it works, it will be beneficial for you to spend some time reading these files.

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

Step 4: Adding 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 some packager information when creating a package. For this, you must export your information with the following commands:

export DEBEMAIL="your@mail.com"
export DEBFULLNAME="Name Lastname"

After this, use the magic command dh_make.

dh_make

After issuing the dh_make command, you should select your package type and press Enter.

Following this step, you will notice a directory in a parent directory with the “.orig” extension. If this doesn’t work, try running the dh_make command with the –createorig parameter.

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

You can also see a new directory named Debian in the present working directory. These directories and files hold all the Debian package-related information about the program.


You need to 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
  • Build-Depends: Dependencies are listed on this line
  • Depends: This line is very important. You specify the dependencies of your package with this value
  • Description: The line where you can enter information about the package

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

3. The changelog File

This file is like your program’s logbook roadmap. If you have done something independent of the source of the program or if you have fixed some 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 prepared Debian package with dpkg, the information in this file is taken as a base.

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

5. Other Files in the Directory

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

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

To proceed to the following stage, remove any files you believe you no longer require. Then rename the file extensions and remove “.ex” from the end. The “.ex” (example) indicates that this is an example file.

Step 6: Building the Package

If you have come this far, you can now prepare the Debian package for your program. For this, run the following command:

dpkg-buildpackage

Another important issue here is to create a GPG for the e-mail address you export as Maintainer.

export DEBEMAIL="example@mail.com"

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

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

dpkg-buildpackage -nc -i

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

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

dpkg -i package-name

Anyone Can Create a Package on Linux

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

If you’re new to GNU/Linux, this may seem perplexing. However, as you can see, preparing a Debian package is simpler than you may think. Of course, building a Debian package requires time and work.

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


Source link

Related Articles

Leave a Reply

Your email address will not be published.

Back to top button