How Create A Debian Package And Local Package Repository

Article By: kevin


BIP media Debian Package debian VPS Templates for cloud servers. This tutorial describes a simple way to create a home made Debian package and include it into a local package repository. Although we could use a existing Debian/Ubuntu package, we will start from scratch by creating our own minimalistic unofficial Debian package. Once our package is ready, we will include it into our local package repository. This tutorial illustrates a very simplistic approach of creating Debian package, however it may serve as a template in many different scenarios.

1. Creating a binary executable

First we need to create a simple program, then compile it and test it. Our program will do nothing else bur print "" on the screen. Here is a code:

int main()
  using namespace std;
  cout << "\n";
return 0;

Save the above code as At this point make sure that you have a compiler installed on your system by executing:

apt-get install build-essential

Compile and execute the code with a following command:

$ g++ -o linuxconfig
$ ./linuxconfig

At this point you should have a binary executable called linuxconfig which prints some string on the screen.

2. Creating a Debian package

Now that we have our small executable binary program ready we can package it up into a Debian package. To do this we will use a dpkg-deb tool. First we need to create a Debian package structure. The only files required to build a debian package are:

  • DEBIAN/control
  • custom files to be part of the package ( not required )

First create a directory called "linuxconfig". This directory will hold all the necessary package files:
$ mkdir linuxconfig

Next, create a control file:

$ cd linuxconfig
$ mkdir DEBIAN

When you're ready, open up the DEBIAN/control file

$ vi DEBIAN/control

and enter a following information:

Package: linuxconfig
Version: 1.0
Section: custom
Priority: optional
Architecture: all
Essential: no
Installed-Size: 1024
Description: Print on the screen

Great, the only thing that is missing is our linuxconfig program. Create a directory which will be used to install the linuxconfig program and copy it into this directory. The best choice for us will be /usr/bin:

$ mkdir -p usr/bin/
$ cp /path/to/linuxconfig usr/bin/

At this point we are ready to create a Debian package.

$ cd ..
$ dpkg-deb --build linuxconfig
dpkg-deb: building package `linuxconfig' in `linuxconfig.deb'.
$ ls
linuxconfig  linuxconfig.deb

Change the name to something like:

mv linuxconfig.deb linuxconfig-1.0_i386.deb

All done ! Our package is ready !

NOTE: this is just an example. A real Debian package that will be submitted part of debian/ubuntu distribution would require more work.

3. Setting up a local package repository

To do this we will need a webserver. In this case we will use apache with the default settings. If you have not done so yet install the apache webserver:

# apt-get install apache2

Navigate your browser to the IP address of your webserver. In our case it is If this is your default apache webserver configuration you should see a page similar to:

It works!

This is the default web page for this server.

The web server software is running but no content has been added, yet.

The location of this default apache welcome page is:


This is exactly the directory where we will store our new Debian package. Create a directory "debian" inside /var/www and copy linuxconfig-1.0_i386.deb inside.

# cd /var/www
# mkdir debian
# cp /path/to/linuxconfig-1.0_i386.deb /var/www/debian/

Still in /var/www create a package list using dpkg-scanpackages:

# dpkg-scanpackages debian /dev/null | gzip -9c > debian/Packages.gz
dpkg-scanpackages: warning: Packages in archive but missing from override file:
dpkg-scanpackages: warning:   linuxconfig
dpkg-scanpackages: info: Wrote 1 entries to output Packages file.

Our home made local Debian package repository is now ready.

4. Accessing local debian package repository

At this point you should be ready to install your own linuxconfig package via our Debian repository. All you need to do is to edit /etc/apt/sources.list and update the package list on a client machine:.

NOTE: change IP address to reflect your webserver

# echo "deb debian/" >> /etc/apt/sources.list
# apt-get update
Ign debian/ Release.gpg
Ign debian/ Translation-en
Ign debian/ Translation-en_AU
Ign debian/ Release                                                      
Ign debian/ Packages                                                     
Get:1 debian/ Packages [303 B] 

All done, now simply install linuxconfig package using apt-get tool:

# apt-get install linuxconfig
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following NEW packages will be installed:
0 upgraded, 1 newly installed, 0 to remove and 8 not upgraded.
Need to get 3,362 B of archives.
After this operation, 1,049 kB of additional disk space will be used.
WARNING: The following packages cannot be authenticated!
Install these packages without verification [y/N]? y
Get:1 debian/ linuxconfig 1.0 [3,362 B]
Fetched 3,362 B in 0s (0 B/s)    
Selecting previously deselected package linuxconfig.
(Reading database ... 95809 files and directories currently installed.)
Unpacking linuxconfig (from .../linuxconfig_1.0_all.deb) ...
Setting up linuxconfig (1.0) ...


# linuxconfig

If you feel that you do not need this package any more, simply remove it from the system with:

# dpkg -P linuxconfig
(Reading database ... 95810 files and directories currently installed.)
Removing linuxconfig ...
# linuxconfig
bash: /usr/bin/linuxconfig: No such file or directory

Tags: , , , , , , , , , , ,

Welcome to the healthcare-only HIPAA - GDPR compliant cloud. Exclusively hosted on a HPC environment!

Learn more or start today by choosing your secure HIPAA - GDPR compliant server's Operating System bellow and pick the package that's best for you.

BIPmd makes it simple to launch in the cloud and scale up as you grow – whether you’re running one virtual machine, thousand or more.

Windows VPS options and add ons
Linux VPS options and add ons


Looking for a custom solution?

Our technicians can provide you with the best custom-made solutionss on the market, no matter whether you're a small business or large enterprise.

Get in touch

Leave a Reply