Mark installing packages as auto installed

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.


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

Tags:

Apt