Debian – compile packages AND keep apt tidy

aptcompilingdebianpackage-management

For the first time in my Linux (Debian) career it seems necessary for me to compile a piece of software myself.

The process of compiling is well described on the project-website. However, there is one thing I don't understand, that keeps me from getting started:

I want to keep my package management (APT) tidy. To compile the project, I need to download a lot of packages (most of them *-dev versions), that I probably wouldn't need, once I finished the compilation.

I don't want to keep those *-dev packages afterwards.

Therefore I wonder if there is a practical way to temporarily install those packages for the compilation-process and afterwards delete them all at once (without having to remember each and every package-name).

Best Answer

If the package happens to be in a debian repo somewhere, you can use build-dep to install the build dependencies and mark those as 'automatically' installed. You can then use autoremove to cleanup those build deps.

apt-get build-dep -o APT::Get::Build-Dep-Automatic=true WhatImBuilding
apt-get autoremove

If whatever you're building doesn't already have a deb package with build deps somewhere, then this technique doesn't work. There is however a debian feature suggestion to add this type of support: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=745769

I suppose you could define a fake package for whatever you're building in a local repo which you manage, and define the build-deps there, allowing the above method to work. That's a bit contrived, though. You can also hand-edit the /var/lib/apt/extended_states file to mark whatever packages you're installing as 'automatic', thus making them eligible for autoremove, but that is probably dangerous.

Related Question