how to uninstall all packages installed by "aptitude build-dep"

Is it possible to undo all changes made by "aptitude build-dep xxxxxx" i.e to un-install all dependencies installed by this command?


For the future, I highly recommend using mk-build-deps -i instead of aptitude build-dep. That leaves a package installed in your system, depending on the build-deps, that you can easily uninstall later.


I found these commands on a Launchpad question:

sudo aptitude markauto $(apt-cache showsrc PACKAGE_NAME | grep Build-Depends | perl -p -e 's/(?:[\[(].+?[\])]|Build-Depends:|,|\|)//g')

There is also an alternative based around sed that copes with brackets in package names:

sudo aptitude markauto $(apt-cache showsrc PACKAGE_NAME | sed -e '/Build-Depends/!d;s/Build-Depends: \|,\|([^)]*),*\|\[[^]]*\]//g')

Note: Replace PACKAGE_NAME with your own package.


I don't think there's an automatic way. Packages installed through build-dep are recorded in the same way as if they'd been directly requested by name.

If you know approximately when you ran aptitude build-dep, you can find which packages got installed when you ran the command by looking through the logs in /var/log/aptitude* or /var/log/apt/*.

You can run apt-cache showsrc PACKAGENAME | grep '^Build-depends:' to list the build dependencies of the package. Review each of them to see if you want them; mark the ones you don't care about as not manually installed (apt-get markauto PACKAGENAME) and flush the non-required packages (apt-get autoremove).