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:
sudo apt-mark auto $(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: I've modified the command above to use apt-mark instead of aptitude, since aptitude is no longer installed by default in Ubuntu (thanks to Cas).
In case you're wondering what the above command does:
- apt-mark 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.