Home Linux Commandline Tips How to Create a Simple (.deb) Debian Package

How to Create a Simple (.deb) Debian Package

The software package format for Debian-based Linux distributions and their associated derivatives can easily be identified by the .deb extension. Debian packages are also attributed to two tar archives. The first archive file contains control information and the second one installable data.

This article will walk us through the creation of a simple Debian package and later demonstrate its installation on any Debian-based system. To cover all the basics needed in creating a Debian package, we will create and package a simple trivial application from scratch.

Creating a Binary Executable in Linux

We are going to come up with a simple C++ program that prints a text string on the standard output. To be certain that this program works, we will have to compile and test it.

So open your terminal editor and create the following file using nano editor.

$ nano debpackage.cc

add the following code snippet.

#include <iostream>
int main() {
    using namespace std;
    cout << "LinuxShellTip's Simple Debian Package! \n";

The g++ compiler needed to compile the above program can be found in the build-essentials package.

$ sudo apt install build-essential 

Let us now compile our C++ program and test the program for the anticipated output:

$ g++ debpackage.cc -o debpackage
$ ./debpackage
Compile C++ Program in Linux
Compile C++ Program in Linux

The above screen capture reveals that we have compiled our C++ code to an executable called debpackage which now prints the string “LinuxShellTip’s Simple Debian Package!” on demand.

Creating a Debian Package in Linux

The executable binary (debpackage) created from compiling the above C++ program is all we need to start creating our Debian package.

Firstly, we need a Debian package structure. The necessary package files need to be hosted under a root package directory:

$ mkdir mypackage
$ mkdir mypackage/DEBIAN

Create a control file inside the DEBIAN directory.

$ nano mypackage/DEBIAN/control 

Populate it with the following info:

Package: debpackage
Version: 0.1
Section: custom
Priority: optional
Architecture: amd64
Essential: no
Installed-Size: 1024
Maintainer: ubuntumint.com
Description: Acknowledge ubuntumint.com tutorials

The Debian package structure is almost complete. Let us create the following final directories:

$ mkdir -p mypackage/usr/bin

The created mypackage/usr/bin directory is the installation directory for the executable binary program debpackage we created earlier. This program executable needs to be copied to this directory:

$ cp debpackage mypackage/usr/bin 

The dpkg-deb tool is needed to create a Debian package, we, therefore, need to point it to the above-created directory structure in the following manner:

$ dpkg-deb --build mypackage
Create Debian Package
Create Debian Package

We can confirm that the .deb package was created:

$ ls -l mypackage.deb
Check Debian Package
Check Debian Package

Please note that the steps followed to create the above .deb package reference a simplified approach as creating an official package will require a more detailed workaround.

Now that our .deb package is created, and we can attempt to install it using the dpkg command.

$ sudo dpkg -i mypackage.deb
Install Debian Package
Install Debian Package

We can also run the Debian package from our terminal to make sure it is executing as per its functional objective.

$ debpackage
Run Debian Package
Run Debian Package

We have successfully created and tested a simple Debian package. This article should serve as the perfect reference template for exploring the creation of more detailed and sophisticated Debian packages.

Ravi Saive
I am an Experienced GNU/Linux expert and a full-stack software developer with over a decade in the field of Linux and Open Source technologies. Founder of TecMint.com, LinuxShellTips.com, and Fossmint.com. Over 150+ million people visited my websites.

Each tutorial at UbuntuMint is created by a team of experienced writers so that it meets our high-quality standards.

Was this article helpful? Please add a comment to show your appreciation and support.

Got something to say? Join the discussion.

Thanks for choosing to leave a comment. Please keep in mind that all comments are moderated according to our comment policy, and your email address will NOT be published or shared. Please Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.