Debian – How to Remove Group of No Longer Needed Packages

debianpackage-management

When building software, I sometimes need to install libraries, binaries, etc. which are only required to build the package but then I forget about removing them, so I end having to cleanup several packages at once; even those that I don't want to remove.

Parsing the log files to find the exact packages is suboptimal and a royal pain if the packages are old enough. Is there a way to facilitate this task?

Best Answer

I would suggest using user tags, which is a characteristic of aptitude (apt binary doesn't have this) would help with that. When installing packages add the --add-user-tag option when installing the packages, for example:

sudo aptitude --add-user-tag build-dep-package build-dep package

and to remove them just use:

sudo aptitude remove '?user-tag(build-dep-package)'

You can also remove the tag along the way with --remove-user-tag build-dep-package.

But this pose a problem, what about if the same package has both tags? Well, you just use the and/not conditionals to prevent that from happening:

sudo aptitude remove '?and(?user-tag(build-dep-package),?not(?user-tag(wanted-packages))'

To manipulate several packages with different tags use or:

sudo aptitude remove '?or(?user-tag(build-dep-package),?user-tag(wanted-packages)'

Through this is very useful in the long run, I haven't found a way to list all the current active tags.

Related Question