How to Install Build Dependencies for a Local Debian/Ubuntu Source Package Not in APT Repositories


2 views

When working with Debian/Ubuntu source packages (.dsc, .orig.tar.gz, and debian.tar.gz) that aren't available in official repositories, the standard apt-get build-dep approach fails. Here's how to handle this professionally.

The most elegant solution involves the devscripts package:


sudo apt-get install devscripts
mk-build-deps -i -r debian/control

This command:

  • Parses the Build-Depends from control file
  • Creates a temporary metapackage
  • Installs all dependencies via apt

For systems without devscripts, use this shell one-liner:


sudo apt-get install $(grep -v "^#" debian/control | grep Build-Depends | cut -d: -f2- | sed 's/([^)]*)//g; s/,/ /g')

Some packages use alternative dependency syntax. For example, when you see:


Build-Depends: debhelper-compat (= 13), libssl-dev (>= 1.1.1)

Use this enhanced command:


sudo apt-get install $(sed -n '/^Build-Depends:/,/^[^ ]/ p' debian/control | \
    grep -v "^ " | cut -d: -f2- | \
    sed 's/([^)]*)//g; s/|//g; s/[<>]=//g; s/[=][^,]*//g; s/,/ /g')

After installing dependencies, verify with:


dpkg-checkbuilddeps

This will list any remaining unmet dependencies.

For production builds, consider setting up a clean chroot:


sudo apt-get install pbuilder
pbuilder create
pbuilder build package.dsc

When working with Debian/Ubuntu source packages (.dsc, .tar.gz, etc.) that aren't available in official repositories, the standard apt-get build-dep approach fails. Here's how to properly handle build dependencies in such cases.

The most reliable approach uses mk-build-deps from the devscripts package:

sudo apt-get install devscripts
mk-build-deps --install --remove debian/control

First extract the dependency list:

grep-dctrl -s Build-Depends -n "" debian/control | \
sed -e 's/([^)]*)//g' -e 's/,\s*/\n/g' | \
xargs sudo apt-get install -y

For complex cases, create a clean build environment:

sudo apt-get install pbuilder
sudo pbuilder create
sudo pbuilder build package.dsc

When dependencies require specific versions, use equivs-control:

equivs-control temp-pkg.control
# Edit the control file
equivs-build temp-pkg.control
sudo dpkg -i temp-pkg.deb

For frequent builds, consider this bash script:

#!/bin/bash
if [ ! -f debian/control ]; then
    echo "Not in package root directory"
    exit 1
fi

if ! command -v mk-build-deps &> /dev/null; then
    sudo apt-get install devscripts
fi

mk-build-deps --install --tool \
"apt-get -y --no-install-recommends" debian/control

If you encounter problems:

  • Check for typos in dependency names
  • Ensure all required repositories are enabled in /etc/apt/sources.list
  • Verify the package builds in a clean chroot using debuild