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 [...]
?
4 Answers
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.
This feature has been added to apt with the --mark-auto
option [1].
https://salsa.debian.org/apt-team/apt/-/commit/c19a3276fe7ecfc132e95b0277e9e68ff364dd92
-
1Nice, this works both using the
apt
command andapt-get
(documented inman apt-get
). Mar 7 at 15:10
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
I use aptitude (sorry, I dislike these types of answers). This is one of my main reasons for using it. Also the dependency management and the conflict resolution tools it contains are very useful to me. You can still use it directly by issuing a command like.
aptitude install okular
And it will mark all new dependencies as automatically installed.
-
1You don't have to use the TUI of aptitude to get these features either. The command
aptitude install vlc vlc-plugin-jack+M
will install vlc normally (marked as manual), but vlc-plugin-jack will be marked as automatically installed (that is what the +M does), so that vlc-plugin-jack will be uninstalled automatically if you uninstall all the packages that require, recommend or suggest vlc-plugin-jack (which is probably just vlc).– pavonJul 8, 2023 at 4:44