Build packages¶
In Ubuntu, packages can be built in several ways, depending on the intended artifacts. We cover the following types of builds:
Source and binary (using
sbuild
for a clean environment)Binary-only (using
sbuild
for a clean environment)Source-only (using
debuild
)Binary-only (using
debuild
and installed build dependencies)
(Many other backends are available, including an schroot
-based backend.)
Only source uploads are permitted to PPAs or the archive. That said, it is best practice to perform a local build and fix any potential issues before uploading it to any archive.
Prerequisites¶
$ sudo apt install sbuild debhelper ubuntu-dev-tools piuparts
All of the following sections assume you have already fetched the packaging and are in the same directory as the debian/
sub-directory.
sbuild
-based builds¶
This is the standard way of building a package for Ubuntu. All of the Debian and Ubuntu infrastructure use sbuild(1). For more information on setting up sbuild(1), refer to the links at the end of this article.
To do a binary-only build of a package using sbuild
, run:
$ sbuild --chroot <RELEASE>-<ARCH>[-shm]
Note
It is possible to use --dist
(-d
) to specify the distribution for the build instead of --chroot
, which explicitly selects the chroot to use, but that causes the produced files to contain the entire chroot name (<RELEASE>-<ARCH>[-shm]
) instead of just <RELEASE>
. An example chroot name is noble-amd64-shm
.
To explicitly run lintian following the build:
$ sbuild -c <RELEASE>-<ARCH>[-shm] --run-lintian [--lintian-opts="-EvIiL +pedantic"]
To build a package without running dh_clean(1), run:
$ sbuild -c <RELEASE>-<ARCH>[-shm] --no-clean-source
To build both a binary and a source package with one sbuild
run:
$ sbuild -c <RELEASE>-<ARCH>[-shm] -s
Note
Launchpad rejects uploads that contains both binaries and sources. However, this is required for uploads to the Debian NEW queue. That said, uploads to Debian with binaries do not migrate to Testing.
Here is a complete, working example of running autopkgtest(1) following the build:
$ sbuild -c noble-amd64-shm --run-autopkgtest \
--autopkgtest-virt-server=qemu \
--autopkgtest-virt-server-opt="/path/to/autopkgtest-noble-amd64.img" \
--autopkgtest-opt="--apt-pocket=proposed=src:qt6-base" \
--autopkgtest-opt="-U" --autopkgtest-opt="--ram-size=12000" \
--autopkgtest-opt="--setup-commands='apt-get -y install aptitude \
&& aptitude -t noble-proposed -y install qt6-base-dev=6.8.1+dfsg-0ubuntu1'"
Building with debuild
¶
debuild(1) (short for dpkg-buildpackage(1)) is another tool used to build Debian packages. It is part of the debhelper(7) package and written in Perl.
Ubuntu maintains its own version of the debhelper
package. Therefore, packages built on Debian may be slightly different than packages built on Ubuntu.
Source-only builds¶
To build a source package without including the upstream tarball, run:
$ debuild -S -d
To build a source package with the upstream tarball, run:
$ debuild -S -d -sa
To build a source package without running lintian, run:
$ debuild --no-lintian -S -d
Note
The --no-lintian
flag only works in this case if it is first.
To build a source package without running dh_clean(1), run:
$ debuild -S -d -nc
Note
This tends to fix failures regarding missing build dependencies.
Local binary-only builds¶
This is really only useful for packages you need to test locally or packages with minimal build dependencies. Otherwise use sbuild(1).
To do a binary-only build of a package, run:
$ debuild -b
Further reading¶
Debian New Maintainers’ Guide: Building the package