Skip to content

Debian - Installing and using pbuilder

Though sbuild is the primary build agent for Debian, pbuilder is still very popular and has some features yet to be found in sbuild, the --twice switch for example.

This tutorial will detail the installation, configuration and use of pbuilder.

First we install pbuilder.

sudo apt install pbuilder


Now we will generate the pbuilder base system tarball for Debian unstable.

sudo pbuilder create --debootstrapopts --variant=buildd --distribution unstable


That simple... Let's build a package.

dget https://deb.debian.org/debian/pool/main/d/ddcutil/ddcutil_2.2.0-2.dsc


sudo pbuilder build ddcutil_2.2.0-2.dsc


The build should complete with success. Let's check below.

ls -1 /var/cache/pbuilder/result/


Output:

philwyett@debian:~$ ls -1 /var/cache/pbuilder/result/
ddcutil_2.2.0-2_amd64.buildinfo
ddcutil_2.2.0-2_amd64.changes
ddcutil_2.2.0-2_amd64.deb
ddcutil_2.2.0-2.debian.tar.xz
ddcutil_2.2.0-2.dsc
ddcutil_2.2.0-2_source.changes
ddcutil-dbgsym_2.2.0-2_amd64.deb
libddcutil5_2.2.0-2_amd64.deb
libddcutil5-dbgsym_2.2.0-2_amd64.deb
libddcutil-dev_2.2.0-2_amd64.deb


Updating your base system tarball

To update your the pbuilder base system tarball with the latest package versions, you can simply run the command below.

sudo pbuilder update


These are the basics.

Building the package for i386

First we clean up after our previous build.

sudo pbuilder clean all


sudo rm -f /var/cache/pbuilder/result/*


Now we remove our previously generated unstable base.

sudo rm -f /var/cache/pbuilder/base.tgz


Now we will generate our unstable i386 base system tarball.

sudo pbuilder create --debootstrapopts --variant=buildd --distribution unstable --architecture i386


Let's now do the i386 build of the package we previously built.

sudo pbuilder build ddcutil_2.2.0-2.dsc


The build should complete with success. Let's check below.

ls -1 /var/cache/pbuilder/result/


Output:

philwyett@debian:~$ ls -1 /var/cache/pbuilder/result/
ddcutil_2.2.0-2.debian.tar.xz
ddcutil_2.2.0-2.dsc
ddcutil_2.2.0-2_i386.buildinfo
ddcutil_2.2.0-2_i386.changes
ddcutil_2.2.0-2_i386.deb
ddcutil_2.2.0-2_source.changes
ddcutil-dbgsym_2.2.0-2_i386.deb
libddcutil5_2.2.0-2_i386.deb
libddcutil5-dbgsym_2.2.0-2_i386.deb
libddcutil-dev_2.2.0-2_i386.deb

As simple as that.

Build after successful build

As you explore Debian and look at more bug reports you will see bugs that are failures to build after successful build. With pbuilder we can use the --twice switch and attempt to do two builds back to back. We do this with the command below.

sudo pbuilder build --twice ddcutil_2.2.0-2.dsc


Try it for yourself.

Building using local packages

On occasion you may need to build a package that depends on one or more packages that is not yet in Debian. To do this we need to some additional configuration.

Add a file called .pbuilderrc to your HOME directory.

In the new .pbuilderrc add the text below and save the file.

#
# The hook dir may already be set/populated!
#
HOOKDIR="$HOME/.config/pbuilder/hooks/"
if [ -n "$DEPS" ] ; then
export DEPSBASE=/var/cache/pbuilder/local_packages
BINDMOUNTS=$DEPSBASE
fi

The folder /var/cache/pbuilder/local_packages is my personal base directory to use, but you may change it to whatever you wish. For now we will create this directory.

sudo mkdir -p /var/cache/pbuilder/local_packages


We next create a directory for the packages as below, you may name it as you wish.

sudo mkdir -p /var/cache/pbuilder/local_packages/kathenas


Next we create the necessary hook.

Create the following directory.

mkdir -p ~/.config/pbuilder/hooks


In the above directory create the file named D05deps.

In the file D05deps add the text below and save the file.

DEPSPATH="$DEPSBASE/$DEPS"
if [ -n "$DEPS" ] && [ -d "$DEPSPATH" ] ; then
apt install --assume-yes apt-utils
( cd "$DEPSPATH"; apt-ftparchive packages . > Packages )
echo "deb [trusted=yes] file://$DEPSPATH ./" >> /etc/apt/sources.list
apt update
fi

We must make this hook file executable. This can be done with the command below.

chmod +x ~/.config/pbuilder/hooks/D05deps


Now we are able to build packages with local dependencies:

1. Build the package you wish to use that is not in Debian.
2. Copy the .deb files from /var/cache/pbuilder/result to /var/cache/pbuilder/local_packages/kathenas
3.Build your package now using the dependencies in /var/cache/pbuilder/local_packages/kathenas using the reference command below.

sudo -E DEPS=kathenas pbuilder build PACKAGE_NAME_AND_VERSION.dsc


I hope you find this tutorial useful and have a good rest of your day.

Flatpak - Remove unused packages and repair

Using flatpak is very useful for when you need a package or few and not pollute your main or any machines file system.

Removing unused packages is simply performed by using the command below in your terminal fo choice.

flatpak uninstall --unused


Verifying and/or repairing your flatpak packages can be done using the command below.

flatpak repair

Debian - June 2025 was a busy-ish month

With freezes in place and much work being done to prepare for Debian 13, it has been a hectic month.

I have been:

1. Reviewing packages and mentoring as part of my contribution to Debian Mentors[1].

2. Making sure the packages I maintain are ready for Debian 13.

3. Doing testing of what will be Debian 13 and its packages.

I have not:

1. Had any movement of my Debian Developer (DD) application.

More to follow soon on this one.

[1] Debian Mentors

Updating and Cleaning using 'apt' and 'dpkg' on the command line

The following are the commands I use to update my Debian (or any apt) system. These commands will help you update your system and then clean update after, including any cruft.

sudo apt update

sudo apt full-upgrade

sudo apt autoremove

sudo apt purge `dpkg --list | grep ^rc | awk '{ print $2; }'`

sudo apt clean all


Hope this helps you update then clean up afterwards.