The Debian package format distributes software effectively across Linux and Debian-based distributions. It automatically manages applications with their source code, configuration files, and deb files to install software on your system. The .deb file in Debian-based operating systems is like an .exe file on Windows — it packages everything needed to install an application.

This guide explains how to build a Debian package from source on Debian 12 using dpkg-buildpackage. The example uses the ProFTPD package, which provides a complete directory structure to demonstrate the full build workflow, from fetching the source to producing the final .deb files.

Quick Answer

Build a Debian package on Debian 12 with these core commands:

sudo apt install dpkg-dev devscripts
apt source proftpd-basic
cd proftpd-dfsg-1.3.8+dfsg
sudo apt build-dep proftpd-basic
dpkg-buildpackage -rfakeroot -b -uc -us

You must first enable deb-src lines in /etc/apt/sources.list and run sudo apt update before fetching the source. Edit the source files as needed between the apt source and dpkg-buildpackage steps.

How to Build a Debian Package

To build the Debian package, update the apt package manager, install dpkg-dev and devscripts, enable deb-src in sources.list, fetch the ProFTPD source, install its build dependencies, and then run dpkg-buildpackage. Make sure your user account has sudo privileges before starting — if not, see how to enable sudo on a user account on Debian 12. Follow the steps below.

Step 1: Setting Prerequisites

First, update the APT package manager to ensure the repository contains the latest packages:

sudo apt update

Running the above command confirms all packages are up to date:

Terminal output of sudo apt update on Debian 12

Next, install dpkg-dev and devscripts. The devscripts package contains all the basic scripts needed to build Debian packages and is essential for Debian developers:

sudo apt install dpkg-dev devscripts
Terminal output of sudo apt install dpkg-dev devscripts on Debian 12

Step 2: Edit Package From Source

You need to edit the sources.list file to add Debian source lines to the APT package, which allows fetching and building packages from source. Open the sources.list file in the nano text editor:

nano /etc/apt/sources.list
Terminal showing the nano editor command to open /etc/apt/sources.list on Debian 12

Inside the file, remove the # from the deb-src lines to uncomment them, as highlighted in the following screenshot:

The /etc/apt/sources.list file in nano with deb-src lines uncommented on Debian 12

Save the file with Ctrl + S and exit the editor with Ctrl + X. Then update APT to include the newly uncommented source lines:

sudo apt update
Terminal output of sudo apt update after enabling deb-src source lines on Debian 12

Step 3: Get Debian Source Package

With the Debian sources added to APT, fetch the proftpd-basic package source. ProFTPD is an open-source FTP server that provides a complete set of source directories for demonstrating the Debian package build process. You can also use crontab on Debian to schedule automated builds of packages like this. Run the following to get the source:

apt source proftpd-basic
Terminal output of apt source proftpd-basic downloading the ProFTPD source package on Debian 12

After fetching, list all the downloaded packages with the ls command:

ls
Terminal showing the ls command listing the downloaded ProFTPD source packages on Debian 12

Step 4: Edit Source Package

Navigate into the proftpd-dfsg-1.3.8+dfsg directory using the cd command:

cd proftpd-dfsg-1.3.8+dfsg

Inside the directory, install the build dependencies for the proftpd-basic package. The build-dep command searches for and installs everything needed to compile the package:

sudo apt build-dep proftpd-basic
Terminal output of sudo apt build-dep proftpd-basic installing build dependencies on Debian 12

Open the data.c file from the src directory in nano to make any configuration changes before building:

nano src/data.c
Terminal showing the nano editor command to open src/data.c in the ProFTPD source directory

Edit the file to apply the configuration highlighted in the following screenshot. If it is already configured, skip this step:

The data.c source file open in nano showing the configuration to be edited before building

Step 5: Build Debian Package

After configuring the source file, build the Debian package using the dpkg-buildpackage command. The -rfakeroot flag allows the package to be installed on the system, -b builds binary packages only, and -uc and -us skip cryptographic and source signing:

dpkg-buildpackage -rfakeroot -b -uc -us

Running this command takes a few moments to build the Debian package. The resulting .deb files can then be installed with apt, just like pre-built packages you would install when setting up software such as VirtualBox on Debian 12:

Terminal output of dpkg-buildpackage -rfakeroot -b -uc -us building the Debian package

The Debian package has been built successfully with binary packages only:

Terminal showing the Debian package build completed successfully with binary packages

Step 6: Verify the Build

Once the package is built, navigate back to the root directory:

cd ..

Use the ls command to list all the Debian packages produced by the build:

ls
Terminal showing ls listing all the Debian packages built from the proftpd-basic source