Knowing how to modify Debian packages on unix systems is a powerful asset for (but not limited to):
- Creating detailed issue/bug reports
- Debugging issues
- Developing new features
The following packages are suggested for Debian package management/modification:
Fetch the sources
If you have
deb-src sources included in your
/etc/apt/sources.list (entries which begin with
deb-src) you can use
apt to fetch package sources. Alternatively you can commonly use
dpkg-source -x (extract source from a dsc-file) or
git to fetch packages.
$ sudo apt source <package>
Dependencies of a package are defined in the
debian control file at
apt build-dep ./ to install the dependencies required to build the package.
Make the desired changes
Now that you have access to all the source files you can make your changes as required.
Incrementing Package Version
When modifying packages you’ll want to append something unique to the package version in order to distinguish your changes from the original package. It’s best practice to update the changelog when making changes. This can be done easily using
debchange package found within the
/sourcePackage/ $ dch --local "-version-append" "change log entry and description of change"
In some cases you’ll want to apply a patch to your package. Patches (which are essentially
diffs can be applied using the
$ wget http://somepatch.com -> /tmp/some-patch $ patch -p1 < /tmp/some-patch
After applying a patch don’t forget to bump the version number using
dch (see “Incrementing Package Version” above). Some patches may require additional steps (such as quilt patch versions). These types of patches will need to be applied using another technique such as
dpkg-source --commit which I won’t cover in this post.
Building the .deb package(s)
Now that you’ve applied your changes and bumped the version number it’s time to build the package. The build process is handled by
dpkg-buildpackage. In this example I use the
-uc arguments to get around potential gnupg signing issues.
$ dpkg-buildpackage -us -uc -b
If you intend to publish the package consider using
debuild which creates all the files necessary for uploading a Debian package. See the
manpage for details.
Building will generate several
.deb files in the parent directory (all for different architectures). Use
apt install or
dpkg to install the
deb for your machine (apt will handle any missing dependencies, dpkg won’t).