Debian Packaging: From Source to Repository
Introduction to Debian Packaging
Understand how Debian packages work, explore the relationship between APT and dpkg, and learn the fundamentals of software packaging on Debian.
Introduction to Debian Packaging
Course: Debian Packaging: From Source to Repository
Lesson: 01 of 20
Level: Beginner to Intermediate
Estimated reading time: 12 minutes
Introduction
When you install software on Debian, you rarely need to download source code, compile it manually, or figure out where every file should go.
Instead, you can simply run:
1
sudo apt install curl
Within seconds, Debian downloads the required files, resolves dependencies, installs the application, and registers it with the system’s package manager.
This experience is made possible by Debian’s package management infrastructure.
But have you ever wondered what happens behind that command?
How does Debian know which files belong to an application? How does it determine which libraries are required? How can it upgrade an application without losing its configuration? And, more importantly, how can you prepare your own software so that other Debian users can install it just as easily?
That’s exactly what this course is about.
Over the next 20 lessons, we’ll learn how to transform an ordinary software project into a properly structured Debian package, distribute it through an APT repository, and make it installable using the same tools Debian users already know.
We’ll use Go to develop a small command-line application called syspeek, and aptly to build and publish our own APT repository.
By the end of this course, you’ll understand not only how to create .deb files, but also how Debian’s packaging ecosystem works as a whole.
1. What Is a Debian Package?
A Debian package is a structured collection of software files and metadata designed to be installed and managed by Debian’s package management system.
A package can contain:
- Executable programs and libraries.
- Configuration files.
- Documentation and manual pages.
- System service definitions.
- Metadata describing the software.
- Information about dependencies and package relationships.
- Scripts required during installation, upgrade, or removal.
The purpose of packaging is to make software installation and maintenance predictable and consistent.
Consider a command-line application that consists of a single executable file.
You could manually copy it into /usr/local/bin and start using it. However, this approach has several limitations:
- The operating system doesn’t know which package owns the executable.
- Dependencies aren’t automatically managed.
- Removing the application requires manual cleanup.
- Upgrading the application becomes your responsibility.
- Other users cannot easily install it through their package manager.
Packaging solves these problems by providing a standardized way to distribute and maintain software.
A properly packaged application becomes part of the operating system’s package management ecosystem.
2. Understanding the Debian Package Ecosystem
Before creating packages, we need to understand the main components involved in the process.
There are four important concepts:
| Component | Responsibility |
|---|---|
dpkg |
Installs, removes, and manages local Debian packages. |
| APT | Resolves dependencies and manages packages from software repositories. |
| Debian Source Package | Contains the source material and packaging instructions. |
| Debian Binary Package | Contains the installable files and package metadata. |
These components work together, but they serve different purposes.
2.1. dpkg: The Low-Level Package Manager
dpkg is the underlying package management tool used by Debian.
It is responsible for operations such as:
- Installing
.debfiles. - Removing installed packages.
- Querying installed package information.
- Inspecting package archives.
- Managing the package database.
For example, you can inspect an installed package using:
1
dpkg -l curl
Or display detailed information:
1
dpkg-query -s curl
You can also list the files installed by a package:
1
dpkg -L curl
Notice that dpkg works directly with packages. It does not independently provide APT’s repository discovery and dependency-resolution workflow.
2.2. APT: The High-Level Package Management Tool
APT stands for Advanced Package Tool.
It provides a higher-level interface for managing software distributed through package repositories.
For example:
1
sudo apt update
Refreshes the available package information.
1
sudo apt install curl
Installs a package and resolves its dependencies.
1
sudo apt upgrade
Upgrades installed packages when newer versions are available.
APT communicates with configured repositories, retrieves package metadata, calculates dependency requirements, and coordinates package installation through dpkg.
This distinction is important:
APT manages the broader package-management workflow, while dpkg performs the underlying local package operations.
2.3. How APT and dpkg Work Together
Consider what happens when you execute:
1
sudo apt install curl
The simplified process looks like this:
- APT reads the configured repository information.
- It identifies available versions of
curl. - It determines which dependencies are required.
- It downloads the required
.debpackages. - It invokes the lower-level package management mechanisms.
dpkginstalls the downloaded packages.- The system’s package database is updated.
This relationship is one of the fundamental concepts in Debian packaging.
3. Source Packages vs. Binary Packages
One of the most important distinctions in Debian packaging is the difference between source packages and binary packages.
They are related, but they are not the same thing.
3.1. Binary Packages
A binary package is the installable package that most Debian users interact with.
Binary packages normally have the .deb extension.
For example:
1
curl_8.x.x-1_amd64.deb
A binary package contains the files required to install and use the software on a compatible system.
It can include:
1
2
3
4
5
6
7
8
9
10
usr/
├── bin/
│ └── syspeek
│
└── share/
├── doc/
│ └── syspeek/
└── man/
└── man1/
└── syspeek.1.gz
This is an illustrative installation layout, not the internal archive layout of a .deb file.
The package also contains metadata describing its identity, version, architecture, dependencies, and other information required by the package manager.
Binary packages are what users ultimately install through APT.
3.2. Source Packages
A source package contains the material required to build one or more binary packages.
It generally includes:
- The original software source code.
- Debian-specific packaging files.
- Build instructions.
- Dependency declarations.
- Copyright and licensing information.
- Any Debian-specific modifications.
For a typical non-native package using the 3.0 (quilt) source format, the source package consists of files resembling:
1
2
3
syspeek_1.0.0-1.dsc
syspeek_1.0.0.orig.tar.gz
syspeek_1.0.0-1.debian.tar.xz
These files serve different purposes:
| File | Purpose |
|---|---|
.dsc |
Describes the source package and references its component files. |
.orig.tar.gz |
Contains the original upstream source code. |
.debian.tar.xz |
Contains Debian-specific packaging files and changes. |
The exact filenames and compression formats can vary.
A source package is not necessarily a single archive. It is a collection of related files that together describe the source and how it should be packaged.
3.3. How They Relate to Each Other
The general relationship looks like this:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
Upstream Source Code
|
v
Debian Packaging Files
|
v
Source Package
|
v
Build Process
|
v
Binary Package
|
v
.deb File
|
v
APT Repository
|
v
Debian Users
The source package is the input to the packaging process.
The binary package is one of its possible outputs.
A single source package can produce multiple binary packages. For example, a project might produce separate packages for its executable, development headers, and documentation.
For our syspeek project, we’ll initially produce one binary package.
4. What Happens Inside a .deb File?
A .deb file is a structured archive containing both the files to be installed and metadata describing the package.
It is not simply a compressed executable.
A typical binary package contains three main archive components:
1
2
3
4
5
6
7
.deb
│
├── debian-binary
│
├── control.tar.*
│
└── data.tar.*
Their responsibilities are:
debian-binary
Identifies the Debian binary package format version.
control.tar.*
Contains package metadata and related control files. Depending on the package, these can include:
control: Package metadata.md5sums: File checksum information.conffiles: Configuration file information.preinst: Pre-installation script.postinst: Post-installation script.prerm: Pre-removal script.postrm: Post-removal script.
Not every package contains every file.
data.tar.*
Contains the actual filesystem content that will be installed.
This can include executables, libraries, documentation, configuration files, and other resources.
Inspecting a Debian Package
Let’s examine an existing package without installing it.
First, download the hello package:
1
apt download hello
This downloads the binary package into the current directory.
Next, inspect its metadata:
1
dpkg-deb --info ./hello_*.deb
You can also inspect the files contained in the package:
1
dpkg-deb --contents ./hello_*.deb
These commands provide a practical introduction to the structure of Debian binary packages.
You can also extract the package contents without installing it:
1
2
3
mkdir hello-extracted
dpkg-deb --extract ./hello_*.deb hello-extracted/
The extracted directory now contains the filesystem content that would be installed by the package.
This is particularly useful when investigating how existing Debian packages organize their files.
5. What Is a Debian Repository?
So far, we’ve discussed individual packages.
But how does APT know where to find them?
This is where Debian repositories come into the picture.
A Debian repository is a structured collection of packages and metadata that allows package management tools to discover, download, and verify software.
Debian maintains official repositories containing thousands of packages.
Third-party developers and organizations can also publish their own repositories.
A simplified repository might look like this:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
repository/
│
├── dists/
│ └── stable/
│ ├── InRelease
│ └── main/
│ └── binary-amd64/
│ ├── Packages
│ └── Packages.gz
│
└── pool/
└── main/
└── s/
└── syspeek/
└── syspeek_1.0.0-1_amd64.deb
The two main directories have different responsibilities.
pool/
Contains the actual package files.
dists/
Contains repository metadata organized by distribution, component, and architecture.
APT uses this metadata to discover available packages and determine which versions can be installed.
Repository metadata also contains checksums that allow clients to verify downloaded package files against the published metadata.
Why Do We Need a Repository?
Imagine you’ve developed a command-line application and want other Debian users to install it.
You could simply send them a .deb file.
However, this approach doesn’t provide a convenient mechanism for discovering new versions, resolving dependencies across repositories, or receiving updates through the normal package management workflow.
Instead, you can publish your package in an APT repository.
Users can then configure their systems to use that repository and install your software with:
1
2
sudo apt update
sudo apt install syspeek
This is the distribution model we’ll implement later in this course using aptly.
6. What Does Packaging Actually Involve?
Packaging is much more than converting an executable into a .deb file.
A proper Debian package must describe how the software should be built, installed, configured, upgraded, and removed.
Let’s look at some of the responsibilities involved.
6.1. Package Metadata
Every package needs information such as:
- Package name.
- Version.
- Architecture.
- Maintainer.
- Description.
- Dependencies.
This information allows package management tools to identify and manage the software correctly.
6.2. Build Dependencies
Some software requires additional tools or libraries during compilation.
For example, building a Go application requires a Go toolchain.
These requirements are called build dependencies.
They are different from runtime dependencies, which are required when the installed application executes.
We’ll examine this distinction in detail when we create our first Debian packaging metadata.
6.3. Filesystem Layout
Debian packages should install files into appropriate locations.
For example:
| Path | Typical purpose |
|---|---|
/usr/bin/ |
Executable programs |
/usr/lib/ |
Libraries and architecture-dependent application files |
/etc/ |
System-wide configuration |
/usr/share/doc/ |
Package documentation |
/usr/share/man/ |
Manual pages |
/usr/share/applications/ |
Desktop application entries |
Choosing the correct installation paths is an important part of producing a well-integrated Debian package.
6.4. Installation and Removal
A package should integrate properly with the operating system.
This includes handling configuration files, permissions, service definitions, and package lifecycle operations when applicable.
A properly packaged application should not leave unnecessary files or unexpected system modifications behind when removed.
6.5. Quality and Policy Compliance
Debian has a formal set of technical requirements known as the Debian Policy.
It defines many aspects of package structure, dependencies, filesystem layout, metadata, and system integration.
We don’t need to memorize the entire policy before starting.
However, throughout this course, we’ll use its requirements as the reference for making packaging decisions.
7. Introducing Our Practical Project: Syspeek
Throughout this course, we’ll develop and package a small Go application called syspeek.
The application will display basic information about a Linux system.
Its planned features include:
| Feature | Description |
|---|---|
| Operating System | Distribution and version information |
| CPU | Processor information |
| Memory | Total and available memory |
| Disk | Filesystem usage |
| JSON Output | Machine-readable system information |
| Version | Application version information |
The goal isn’t to build a sophisticated system monitoring application.
Instead, we want a realistic software project that lets us explore the complete Debian packaging lifecycle without introducing unnecessary complexity.
We’ll gradually move from ordinary Go source code to a properly structured Debian source package, then produce an installable .deb package.
Finally, we’ll publish it through our own APT repository.
The overall workflow will look like this:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
Go Source Code
|
v
Debian Packaging
|
v
Source Package
|
v
Package Building
|
v
Binary Package
|
v
Package Testing
|
v
APT Repository
|
v
Package Installation
Every stage will be explained and demonstrated in the upcoming lessons.
8. Exploring Your Existing Debian System
Before moving on, let’s perform a few simple exercises using packages already installed on your system.
These commands don’t modify your system.
Exercise 1: Identify an Installed Package
Run:
1
dpkg-query -W curl
This displays the package name and installed version.
Exercise 2: Inspect Package Metadata
Run:
1
apt show curl
Look at the following fields:
- Package
- Version
- Architecture
- Depends
- Description
Notice how much information is associated with a package beyond its executable files.
Exercise 3: Explore Package Dependencies
Run:
1
apt-cache depends curl
This displays the dependency relationships declared for the package.
Exercise 4: Explore Installed Files
Run:
1
dpkg -L curl
Observe where Debian has installed the package’s files.
These exercises will help you understand how Debian manages software before we start creating packages ourselves.
9. Key Takeaways
In this lesson, we’ve explored the fundamental concepts behind Debian packaging.
Here are the most important points to remember:
- A Debian package is a structured collection of software files and metadata.
dpkgis responsible for low-level package operations.- APT provides higher-level package management, including dependency resolution and repository access.
- Source packages contain the material and instructions required to build binary packages.
- Binary packages are the installable packages distributed to users.
- APT repositories provide packages and metadata in a structured format.
- Proper packaging involves much more than creating a
.debfile.
Understanding these concepts will make the practical steps in the following lessons much easier.
10. What’s Next?
Now that we understand the general architecture of Debian packaging, it’s time to look more closely at the actual package formats.
In the next lesson, we’ll explore the anatomy of Debian packages in greater detail.
We’ll examine source package formats, binary package contents, package metadata, and the relationship between upstream source code and Debian-specific packaging files.
Next lesson: 02 — Anatomy of a Debian Package
References and Further Reading
The following resources are official Debian documentation and useful references for this course.
- Debian Policy Manual — The technical standards and requirements for Debian packages.
- Debian FAQ: Basics of the Package Management System — An introduction to Debian package management.
- Debian Reference: Package Management — A practical overview of APT and package management.
- Guide for Debian Maintainers — A guide to creating Debian source packages.
- Debian Packaging Wiki — Documentation, tools, and resources for Debian package maintainers.
End of Lesson 01 / 20