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:

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

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

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

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

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

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

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

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

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

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:

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

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
