16

Is there a command that installs all the unmet build dependencies that dpkg-checkbuilddeps would list?

I tried to sed the output and give it to apt-get install, but it seems very hacky and for some reason didn't work in some environments.

sudo apt-get install --yes $(dpkg-checkbuilddeps | sed 's/([^)]*)//g' | sed 's/dpkg-checkbuilddeps:\serror:\sUnmet build dependencies://g')

Is there a better way?

Stephen Kitt
  • 434,908
Forivin
  • 847

3 Answers3

31

I use mk-build-deps from the devscripts package for this (you’ll also need equivs).

mk-build-deps

will build a package depending on all the build-dependencies in the debian/control control file; that package can then be installed using apt, which will also install all the missing dependencies.

The advantage of this approach is that uninstalling the dependency package, once you’ve finished with it, will also identify any build-dependencies which could also be uninstalled.

To reduce manual steps, the following command can be used:

mk-build-deps --install --root-cmd sudo --remove

The end result of this is that all the build dependencies are installed, but not the newly-generated build-dependency package itself: it’s installed (--install), along with all its dependencies, and then removed (--remove), but the dependencies are left in place.

Stephen Kitt
  • 434,908
4

Try the following:

dpkg-checkbuilddeps 2>&1 | sed 's/dpkg-checkbuilddeps:\serror:\sUnmet build dependencies: //g' | sed 's/[\(][^)]*[\)] //g'

First of all, dpkg-checkbuilddeps prints out the error to stderr not stdout. So it needs to be redirected to stdout to use pipeline.

Here is how to Redirect stderr and stdout in Bash

You used the regex ([^)]*) on:

sed 's/([^)]*)//g'

But it should be:

sed 's/[\(][^)]*[\)]//g'

Reference: Using sed to delete a string between parentheses

Jeff Schaller
  • 67,283
  • 35
  • 116
  • 255
1

Combining the 2 methods previously mentioned worked for me:

sudo apt-get install \
    --yes $(dpkg-checkbuilddeps 2>&1 | sed -e 's/dpkg-checkbuilddeps:\serror:\sUnmet build dependencies: //g' -e  's/[\(][^)]*[\)] //g')
Archemar
  • 31,554
akme
  • 11
  • This does not work when the last dependency in the line has a version specifier (e.g. ... packagename (>= 1.0.0) because of the mandatory white space at the end of the second regular expression. Use 's/[\(][^)]*[\)] *//g' to cover this case. – sebix Aug 21 '23 at 11:58