Creating a Debian Package (.deb)

Batur Orkun
2 min readMay 13, 2019

Step 1

Create a directory named your package name. Ex: “my_package”

# mkdir my_package
Create DEBIAN subdirectory in “my_package” directory.

# mkdir my_package/DEBIAN

Step 2

Create control and installation files as following. The permission of these files must be 755.


preinst is responsible for doing requisites before installing.

postinst is responsible for doing requisites after installing.

prerm is responsible for doing requisites before uninstalling. Ex: Stop running services.

postrm is responsible for doing requisites after uninstalling. Ex: Delete config and log files.

Step 3

Write parameters and commands in these files. Control files have a lot of parameters. You can find simple examples below.

Package: batur
Version: 0.0.1
Source: batur
Priority: optional
Architecture: all

If there are some depends, in other words, your package needs some other packages, you must set it in control files. Missing packages will be installed after getting user confirmation.

Package: Leapvox-Mail-Server
Version: 0.0.1
Source: Leapvox
Section: mail
Priority: optional
Architecture: all
Description: Leapvox Mail Server

You can set a private version for depends.

Package: batur-orkun-1.0.0
Version: 1.0.0
Architecture: amd64
Installed-Size: 1000
Depends: python2.6 (>= 2.6.5), python-numpy (>= 1.3.0), python-scipy (>= 0.7.0)
Priority: optional
Description: Batur Orkun’un ozel debian paketidir.

Example of “preinst” script:

set -e
echo Kurulum basliyor….
service postfix stop
service saslauthd stop
service dovecot stop
rm -rf /etc/default/saslauthd
exit 0;

Example of “postinst” script:

set -e
chmod o= /etc/postfix/mysql-virtual_*.cf
chgrp postfix /etc/postfix/mysql-virtual_*.cf

chmod o= /etc/pam.d/smtp
chmod o= /etc/postfix/sasl/smtpd.conf
chmod o= /etc/postfix/smtpd.key

adduser postfix sasl
groupadd -g 5000 vmail
useradd -g vmail -u 5000 vmail -d /var/vmail -m

postconf -e ‘myhostname =’
postconf -e ‘mydestination =, localhost, localhost.localdomain’
postconf -e ‘mynetworks =’
echo “dovecot unix — n n — — pipe” >> /etc/postfix/
echo ” flags=DRhu user=vmail:vmail argv=/usr/lib/dovecot/deliver -d ${recipient}” >> /etc/postfix/
mv /etc/default/saslauthd__ /etc/default/saslauthd
service postfix restart
service saslauthd restart
service dovecot restart

echo “Installation was completed successfully”
echo Batur Orkun
exit 0;

Step 4

Config files you want to copy are created according to the full directory structure in the “my_package” directory. my_package directory will be the root directory of all files in the package.


If you want to create “/usr/bin/my_file” file and “/var/www/my_dir” directory, your directory structure should be like that:


Step 5

You are ready to build your package.

$ dpkg-deb –build my_package

After this process, if you have not any error, you will have the file named “my_package.deb”