16

When I want to compile something from source in Ubuntu/Debian, I usually get build-dependencies by running "sudo apt-get build-dep PACKAGE_NAME" in the terminal.

They are (usually) useless once the compilation job is done.

So, how do I remove all build-dependencies for a particular package?

5 Answers 5

11

Tumbleweed writes:

For the future, I highly recommend using mk-build-deps ... instead of aptitude build-dep. That leaves a package ... in your system, [which has dependencies] on the build-deps, that you can easily uninstall later.

mk-build-deps can be installed with sudo apt install devscripts

1
  • 2
    Note that you may also need to run sudo apt install equivs because devscripts only Suggests that package and it's actually required to execute mk-build-deps. Jul 21, 2021 at 13:32
7

To find out the build-dependencies of a program you can run apt-cache showsrc pkgname and that will list, amongst other information the Build-Depends, which are often files ending in -dev; although it is worth checking if any of the files (particularly those not marked -dev) are required by other programs. You could find this out by using apt-cache depends file and apt-cache rdepends file. The following example is for Shotwell:

apt-cache showsrc shotwell

Build-Depends: debhelper (>= 7.0.50~), m4, valac-0.16 (>= 0.15), libgee-dev (>= 0.5.0), libgtk-3-dev (>= 3.0.11), libexif-dev (>= 0.6.16), libsqlite3-dev (>= 3.5.9), libgexiv2-dev (>= 0.4.1-1build1), libgnomevfs2-dev (>= 2.24.2), libgphoto2-2-dev (>= 2.4.2), libsoup2.4-dev (>= 2.26.0), libxml2 (>= 2.6.32), libunique-3.0-dev (>= 1.0.0), libwebkitgtk-3.0-dev (>= 1.1.5), libgudev-1.0-dev (>= 145), libdbus-glib-1-dev (>= 0.80), libraw-dev (>= 0.13.1-2), libusb-dev, libjson-glib-dev (>= 0.7.6), libgstreamer0.10-dev (>= 0.10.28), libgstreamer-plugins-base0.10-dev (>= 0.10.32), python-scour, libunity-dev, liblaunchpad-integration-3.0-dev (>= 0.1.36), librest-dev

There is a command to do it all in one go at the webupd8 site, but I have found that it doesn't seem to work reliably with the current version of Ubuntu in that it seems to remove too much. I tried it with Pinta and it suggested removing the entire mono library. There is discussion of such problems with using commands like the webupd8 one at Launchpad. Be very careful when experimenting with any 'solutions' you might find.

It is a shame that there is no autoremove command for build-dep installed packages.

2
  • 1
    I tried aptitude method & yes, you are right , it removes too much...may because of cross-dependencies. One another mothod i found is to pass the following option (while using build-dep command): sudo apt-get build-dep -o APT::Get::Build-Dep-Automatic=true PACKAGE_NAME. Now they can be removed with apt-get autoremove. But this works only after removing the main package. Aug 26, 2012 at 10:26
  • 2
    Anyway, I just learned that the proper-way to do it, is using pbuilder. So no-one has to worry about installing/uninstalling dependencies. Aug 26, 2012 at 10:28
4

Option 1:

Remember which packages were installed by sudo apt-get build-dep PACKAGE_NAME and remove them after building.

Option 2:

apt-cache showsrc gives a great deal of information about source packages, including a list of build-depends.

apt-cache showsrc PACKAGE_NAME

For example:

$ apt-cache showsrc pithos
Package: pithos
Binary: pithos
Version: 0.3.17~git07dcbd86a1
Section: python
Maintainer: Kevin Mehall <[email protected]>
Build-Depends: cdbs (>= 0.4.43), debhelper (>= 6), python, python-central (>= 0.6.11), python-distutils-extra (>= 2.10)
Architecture: all
Standards-Version: 3.8.2
Format: 1.0
Directory: pool/main/p/pithos
Files:
 cdf2129923e62bb62c246965453b40bd 2023031 pithos_0.3.17~git07dcbd86a1.tar.gz
 97689e8ada8be527d689f2c83415d3b0 1544 pithos_0.3.17~git07dcbd86a1.dsc
Python-Version: current
Checksums-Sha1: 35cbf3ae52922e50a0b81afcce2cd97a86afb254 2023031 pithos_0.3.17~git07dcbd86a1.tar.gz
Package-List: pithos deb python extra
Checksums-Sha256: 2b704d86f3dc1d36d180177d11e578bdcf74ea97b09b530144afe754e570b262 2023031 pithos_0.3.17~git07dcbd86a1.tar.gz
$ sudo apt-get remove cdbs debhelper python python-central python-distutils-extra

The risk with this option is that you may remove a package that is important for something besides building PACKAGE_NAME. Just read through the list of packages to be removed before going ahead.

4

So that packages you need don't get removed:

read -p "Enter package name: " packageName
sudo apt-mark auto $(apt-cache showsrc $packageName | sed -e '/Build-Depends/!d;s/Build-Depends: \|,\|([^)]*),*\|\[[^]]*\]//g' | sed -E 's/\|//g; s/<.*>//g')
sudo apt-mark manual build-essential fakeroot devscripts
sudo apt autoremove --purge

However, you really should consider using mk-build-deps in the future to avoid this package trainwreck.

1

You can use the /var/log/apt/history.log for this. Use grep to find the correct line and pass the cleaned up list of packages to apt remove:

 apt remove $(cat /var/log/apt/history.log | grep "Install: fontconf" | sed -re 's/\([^)]+\)//g' -re 's/:[^ ]+//g' -re 's/, //g' -re 's/^Install: //g')

This example was used to remove packages from a apt build-dep linux.

Check the packages listed in apt the remove operation carefully.

Execute also a apt autoremove, just in case.

1

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .