BIP KB:
How Create A Debian Package And Local Package Repository
Article By kevin
![]() |
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 "linuxconfig.org" on the screen. Here is a code:
#includeint main() { using namespace std; cout << "linuxconfig.org\n"; return 0; }
Save the above code as linuxconfig.cc. 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++ linuxconfig.cc -o linuxconfig $ ./linuxconfig linuxconfig.org
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 Maintainer: linuxconfig.org Description: Print linuxconfig.org 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 http://10.1.1.6/. 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:
/var/www
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 http://10.1.1.4 debian/" >> /etc/apt/sources.list # apt-get update Ign http://10.1.1.4 debian/ Release.gpg Ign http://10.1.1.4/ debian/ Translation-en Ign http://10.1.1.4/ debian/ Translation-en_AU Ign http://10.1.1.4 debian/ Release Ign http://10.1.1.4 debian/ Packages Get:1 http://10.1.1.4 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: linuxconfig 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! linuxconfig Install these packages without verification [y/N]? y Get:1 http://10.1.1.4/ 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) ...
Execute:
# linuxconfig linuxconfig.org
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: debian, repository, binary, create deb package, Debian Package, debian package repository, Debian Package Tutorial, executable, local, Local Package Repository, package repository, Ubuntu package
Spin Up A VPS Server In No Time Flat
Simple Setup
Full Root Access
Straightforward Pricing
DEPLOY A SECURE VPS SERVER TODAY!Leave a Reply
Feedbacks
![]() This work is licensed under a Creative Commons Attribution- NonCommercial-ShareAlike 4.0 International License. |