Apt-get and its irritating lack of easy selective upgrades

March 7, 2016

One of my many irritations with apt-get is that it doesn't easily allow you to only apply some of the pending updates. Sure, often you want to apply all of the updates (at least all of the unheld updates), but there are any number of cases where you want to be more selective. Sometimes you are in a rush and you want to apply only a few very urgent updates. Sometimes you want to apply updates in a specific order, updating some packages before others. Sometimes you want to apply most updates but temporarily exclude some that you consider low priority or disruptive.

With a package manager like yum (or now dnf) you can easily do either of these. If you just want to exclude some packages, you do that with '--exclude'; if you only want to upgrade some packages, you do that by supplying them as explicit arguments. And it's harmless to be a bit broad in your explicit arguments, because you're specifically only upgrading existing packages; you'll never install new ones out of nowhere.

apt-get does not support this usage as far as I can see. apt-get upgrade takes no package list and has no way of excluding some packages; it is an all or nothing operation, where the only way you have of being selective is to hold packages in advance in order to block their upgrades. In order to upgrade packages selectively, you must turn to 'apt-get install', probably with '--only-upgrade' so that you don't accidentally install new packages. And as far as I can tell this has no equivalent of yum's --exclude, so there's no easy way I can see of saying 'upgrade everything except the following packages'.

(apt-get install does at least support wildcards, or more exactly POSIX regular expressions. I don't know why they decided to use regular expressions instead of shell globbing, but it feels like a very Debian decision, especially the detail that it defaults to matching substrings.)

'apt-get install --only-upgrade PKG ...' solves about half of the problem (although clumsily) so I'm less disgruntled than I was at the start of writing this entry, but it's still not particularly great.

Comments on this page:

By dozzie at 2016-03-07 02:24:00:

This is why I use aptitude as an addition to apt-get.

By Zev Weiss at 2016-03-07 02:36:01:

This has also irritated me about apt-get for some time -- and making matters even worse is that apt-get upgrade silently ignores arguments passed to it! Sane behavior for a command-line tool would be to explicitly reject unrecognized arguments, but apt-get upgrade instead just marches right along, giving at first the (mis-)impression that it's actually going to do what you wanted -- only to then go and upgrade everything instead.

Though I'm sure there are other such brain-damaged clunkers out there, literally the only other command-line tool I can think of off the top of my head that does this is /bin/true (where it's actually not too unreasonable, I'd say).

By Ewen McNeill at 2016-03-07 03:48:13:

"apt-get install PACKAGES" is indeed a common workaround, and I use it frequently. Unfortunately I think it probably sets the "manually installed" flag (well, clears the Auto-Installed flag) on those packages, which means that they will no longer be eligible for "autoremove" if the original package that brought them in as dependencies is removed. (The Auto-Installed flag does not seem well documented online; this stack-exchange advice is one of the clearer explanations I can find quickly.)

By contrast things like MacPorts support the obvious syntax "port upgrade PACKAGES" -- and require an argument, so you use, eg, "port upgrade outdated" to upgrade everything needing an upgrade -- and "port upgrade" by itself just results in an error message. So I do periodically miss having "apt-get upgrade PACKAGES" do something useful.

However, to expand on dozzie's comment, it does look like aptitude supports "aptitude safe-upgrade PACKAGES" to do something similar to what you want. (Plus the concept of install sets if you fiddle with the curses UI.) I'm not sure I can be bothered with the extra typing (and package inventory processing) for one-off command line tasks, but for something in a script it might be worth it.


By vaclav at 2016-03-09 05:17:52:

man apt-mark

Written on 07 March 2016.
« Firefox addons seem unfortunately prone to memory leaks
Why it makes sense for true and false to ignore their arguments »

Page tools: View Source, View Normal, Add Comment.
Login: Password:
Atom Syndication: Recent Comments.

Last modified: Mon Mar 7 01:14:06 2016
This dinky wiki is brought to you by the Insane Hackers Guild, Python sub-branch.