Mark installing packages as auto installed

apt-mark and similar software can mark packages as automatically installed, but can that be done during installation itself, something akin to apt install --mark-auto packages [...]?


Solution 1:

No, you have to run as separate command call apt-mark auto ... Even its action was removed from apt-get.

$ sudo apt-get markauto
Reading package lists... Done
Building dependency tree       
Reading state information... Done
N: This command is deprecated. Please use 'apt-mark auto' and 'apt-mark manual' instead.
E: Handler silently failed

As a workaround, you could store the package list in a variable then use it with both commands. Another option, create a single shell function that run both commands for any input.

Solution 2:

It really seems there is no built-in way of doing this. So I wrote a little script that does the job.

#!/bin/bash -e

NEW_DEPS=$(comm -23 <(xargs -n1 <<< "$@" | sort) <(apt-mark showmanual | sort))

apt install $NEW_DEPS
apt-mark auto $NEW_DEPS

It first filters out any packages that are already installed manually and then installs the rest, setting them to automatically installed afterwards.

I usually use this to temporarily install build dependencies. Suppose I need packages A, B and C to build something and have above script available as autoinstall. I can then use the following procedure to keep the build dependencies from remaining on my system after the build.

sudo autoinstall A B C
# build stuff...
sudo apt autoremove

Solution 3:

This feature has been added to apt with the --mark-auto option [1].

https://salsa.debian.org/apt-team/apt/-/commit/c19a3276fe7ecfc132e95b0277e9e68ff364dd92