Building a Simple Debian Package and Hosting a Local APT Repository

1. Creating a Binary Executable

First, create a simple C++ program that prints a message to the screen.

#include <iostream>

int main()
{
    using namespace std;
    cout << "linuxconfig.org\n";
    return 0;
}

Save the file as linuxconfig.cc.

Install Compiler Toolchain

sudo apt-get install build-essential

Compile and Test

g++ linuxconfig.cc -o linuxconfig
./linuxconfig

Expected output:

linuxconfig.org

At this stage, you have a working executable named linuxconfig.


2. Creating a Debian Package

To package the executable into a Debian package, we use dpkg-deb. A minimal Debian package requires:

  • DEBIAN/control
  • Files to be installed (optional but required for real use)

Create Package Directory Structure

mkdir linuxconfig
cd linuxconfig
mkdir DEBIAN

Create Control File

vi DEBIAN/control

Add the following content:

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

Add Executable to Package

Place the binary under /usr/bin inside the package directory:

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

Build the Package

cd ..
dpkg-deb --build linuxconfig

Rename the package:

mv linuxconfig.deb linuxconfig-1.0_i386.deb

Your Debian package is now ready.

Note: This is a minimal example. Production-quality packages require additional metadata and compliance.


3. Setting Up a Local Debian Package Repository

To distribute your package via APT, set up a simple local repository using Apache.

Install Apache

sudo apt-get install apache2

The default document root is:

/var/www

Create Repository Directory

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

Generate Package Index

dpkg-scanpackages debian /dev/null | gzip -9c > debian/Packages.gz

Your local repository is now ready.


4. Accessing the Local Repository

On a client machine, add the repository to /etc/apt/sources.list:

echo "deb http://10.1.1.4 debian/" | sudo tee -a /etc/apt/sources.list
sudo apt-get update

Now install your package:

sudo apt-get install linuxconfig

Test it:

linuxconfig

Expected output:

linuxconfig.org

5. Removing the Package

If you no longer need the package:

sudo dpkg -P linuxconfig

Verification:

linuxconfig
# bash: /usr/bin/linuxconfig: No such file or directory

Conclusion

This example demonstrates:

  • Building a simple executable
  • Packaging it as a Debian package
  • Hosting it in a local APT repository
  • Installing it via standard package management tools

Understanding Debian packaging and repository mechanics is essential for system administrators, DevOps engineers, and anyone maintaining custom software deployments.

← Previous Post
Next Post →

Leave a Comment