Ubuntu / Linux news and application reviews.

When you want to compile something from source in Ubuntu/Debian, the easiest way to install the dependencies required to compile it is to run (sudo) "apt-get build-dep PACKAGE_NAME". But there is no built-in command to remove these dependencies (like apt-get remove-dep).

But thanks to tvst and Wesley Schwengle, you can undo "apt-get build-dep" by running the following command (firstly install aptitude using "sudo apt-get install aptitude"):
sudo aptitude markauto $(apt-cache showsrc PACKAGE_NAME | sed -e '/Build-Depends/!d;s/Build-Depends: \|,\|([^)]*),*\|\[[^]]*\]//g')
sudo apt-get autoremove
In the above command, replace "PACKAGE_NAME" with the name of the package you've previously ran "apt-get build-dep" for. Running "sudo apt-get autoremove" should then remove all the packages that are build dependencies for PACKAGE_NAME and thus, were installed by the "apt-get build-dep" command.


Update: there are issues with this command and some packages. For instance, trying to undo "apt-get build-dep" for Wine results in marking a huge number of packages as automatically installed. If that happens, running "sudo apt-get install PACKAGES-MARKED-AS-AUTOMATICALLY-INSTALLED" marks the packages as installed so they won't be removed, undoing the command above. So use this with care and only if you know what you're doing!

In case you're wondering what the above command does:
  • aptitude auto - Mark packages as having been automatically installed (so if no package depends on them, they will be removed)
  • apt-cache showsrc - Show source records
  • sed ....: - searches for "Build-Depends:" in the source records and removes useless stuff from the package names (extra characters like parentheses and so on are removed from the output).

To use it as an alias in your ~/.bashrc file, see wilo108's comment below.



Credits for the command: tvst and Wesley Schwengle @ Launchpad.