Debian Packaging: From Source to Repository
Preparing the Debian Packaging Environment
Install and configure the essential tools required to build, inspect, and validate Debian packages.
Preparing the Debian Packaging Environment
Before building our first Debian package, we need a properly configured development environment.
Debian packaging involves more than compiling software. We need tools to build packages, manage dependencies, generate package metadata, inspect the resulting artifacts, and check their quality.
In this lesson, we will install the essential tools and prepare a workspace for our practical project, Syspeek.
Learning Objectives
By the end of this lesson, you will be able to:
- Install the essential Debian packaging tools.
- Understand the purpose of the most important build utilities.
- Verify that your development environment is ready.
- Create a clean workspace for the course project.
- Understand why package builds should eventually happen in isolated environments.
1. Update Your Package Index
Start by updating the local APT package index:
1
sudo apt update
This retrieves the latest package information from the repositories configured on your system.
You can also upgrade installed packages if necessary:
1
sudo apt upgrade
Upgrading is optional for this lesson. On a dedicated development machine, keeping the system reasonably up to date is generally a good idea.
2. Install the Essential Tools
Install the tools we will use throughout the course:
1
2
3
4
5
6
7
8
9
10
11
sudo apt install \
build-essential \
devscripts \
debhelper \
dpkg-dev \
fakeroot \
lintian \
dh-make \
git \
golang-go \
dh-golang
Let’s understand what each package provides.
| Package | Purpose |
|---|---|
build-essential |
Essential compilation tools such as GCC, Make, and related utilities |
devscripts |
Developer utilities, including debuild |
debhelper |
Helpers for automating common Debian packaging tasks |
dpkg-dev |
Tools for building and inspecting Debian packages |
fakeroot |
Simulates certain root privileges during package creation |
lintian |
Checks Debian packages for common policy and packaging issues |
dh-make |
Helps generate an initial Debian packaging template |
git |
Version control for our project |
golang-go |
Go compiler and development tools |
dh-golang |
Debhelper integration for Go packages |
APT will resolve and install the dependencies required by these packages.
3. Understand the Main Build Tools
We will use several commands repeatedly during this course.
dpkg-buildpackage
This is one of the central tools in Debian package development.
It builds Debian source and binary packages using the packaging instructions in the source tree.
We will use it when we start building our own package.
debuild
debuild is a higher-level wrapper around Debian build tools.
It simplifies common build operations and can run additional checks.
For example:
1
debuild -us -uc
The options -us and -uc skip signing the source package and changes file. They are useful for local experiments, not for publishing signed packages.
debhelper
Debhelper provides commands and build-system integration that simplify packaging.
One of its central tools is dh, which coordinates common packaging steps.
Instead of manually implementing every packaging operation, we can rely on standardized helpers.
fakeroot
Building a Debian package may require file ownership and permission metadata that would normally need root privileges.
fakeroot helps simulate these operations without running the entire build as root.
It does not grant real root privileges.
lintian
A package can build successfully and still contain packaging mistakes.
lintian checks packages and source packages for many common issues.
We will use it to inspect our packages before publishing them.
4. Verify the Installation
Let’s confirm that the important tools are available.
Check the Debian package builder:
1
dpkg-buildpackage --version
Check debhelper:
1
dh --version
Check the Go compiler:
1
go version
Check Lintian:
1
lintian --version
Check Git:
1
git --version
You should see version information for each tool.
You can also inspect the installed versions through APT:
1
2
3
4
5
6
7
8
apt list --installed \
build-essential \
devscripts \
debhelper \
dpkg-dev \
fakeroot \
lintian \
golang-go
The exact versions will depend on your Debian or Ubuntu release.
5. Create a Dedicated Workspace
Let’s keep our course files separate from unrelated projects.
Create a workspace:
1
2
mkdir -p ~/packaging-lab
cd ~/packaging-lab
Create a directory for Syspeek:
1
2
mkdir -p syspeek
cd syspeek
Check the directory structure:
1
pwd
Our workspace will eventually contain the application source code and Debian packaging files.
For now, it is intentionally empty.
We will introduce the actual Go application in a later lesson.
6. Check Your Debian Environment
It is useful to know which distribution and architecture we are working with.
Display operating system information:
1
cat /etc/os-release
Display the system architecture:
1
dpkg --print-architecture
Display the kernel architecture:
1
uname -m
These commands provide useful context when building packages.
For example, dpkg --print-architecture may return:
1
amd64
This is the architecture identifier used by Debian packaging tools.
Do not confuse it with the output of uname -m, which may use a different naming convention, such as x86_64.
7. Why We Need Isolated Build Environments
At this point, we have installed the tools and prepared a workspace.
However, there is one important problem with building packages directly on our everyday development machine.
The build may accidentally depend on libraries or tools that are installed on the host but are not declared correctly in the package metadata.
This can produce a package that builds successfully on one machine but fails on another.
A clean build environment helps prevent this problem.
Debian developers commonly use tools such as:
sbuildpbuildermmdebstrap
These tools help create clean environments in which package dependencies are installed explicitly before the build begins.
We will explore isolated builds in the next lesson.
For now, remember this principle:
A successful build on your own machine does not automatically mean your package is reproducible or portable.
8. What We Learned
In this lesson, we prepared our Debian packaging environment.
We installed:
- Build and compilation tools.
- Debian packaging utilities.
- Package validation tools.
- Go development tools.
- Version-control utilities.
We also created a dedicated workspace for Syspeek and examined the operating system and architecture information.
Our environment is now ready for the next stage.
Exercises
Before moving on, try the following:
- Run
apt show debhelperand inspect its package information. - Find which package provides the
dpkg-buildpackagecommand. - Run
dh --helpand explore the available options. - Execute
dpkg --print-architectureand compare it withuname -m. - Run
lintian --helpand identify how it accepts a package file.
What’s Next?
Our development tools are installed, but we have not yet addressed one of the most important aspects of reliable package building: isolation.
In the next lesson, we will explore clean build environments and learn how to build Debian packages without depending on accidental tools or libraries installed on the host system.