13

This might be a possible bug, but it is something that has been bothering me for a couple of days now.

The difference between apt-get upgrade and apt-get dist-upgrade has been both well-known and well-established by now i.e. upgrade installs/upgrades while dist-upgrade is capable of install/remove/upgrade if package removal happens to be necessary for either an installation or upgrading of another package. The difference in packages can be easily discovered with something like

(the following is a quick and dirty method and will need sudo password to be entered already in the terminal for copy pasting. Also, as I have several packages and drivers I patched myself that I need kept back for functionality, I included the OR in the awk to extract only those to be installed and those to be upgraded, and not those listed as to be kept back, but the following should work even if those lines are not present in your apt upgrade outputs) :

$echo -e 'n' | sudo apt-get dist-upgrade | awk '
/be installed|be upgraded/{f=1;next}; /not upgraded|kept back/{f=0}f' | awk '
BEGIN {RS=" ";} {print $0}
' | grep . > apt_get_dist_list

$echo -e 'n' | sudo apt-get upgrade | awk '
/be installed|be upgraded/{f=1;next}; /not upgraded|kept back/{f=0}f' |  awk '
BEGIN {RS=" ";} {print $0}
' | grep . > apt_get_upgrade_list

and when I compare the two outputs with:

$diff apt_get_dist_list apt_get_upgrade_list | grep -E '<|>'

in my case I get the following:

< gir1.2-nm-1.0
< libcpupower2
< linux-kbuild-5.2
< blueman
< linux-cpupower
< linux-headers-amd64
< linux-image-amd64
< pdf-parser

Which makes the difference quite clear, especially given the presence of linux-header-* and linux-image-* in apt-get dist-upgrade

Now if I repeat the same process for apt upgrade and apt full-upgrade

$echo -e 'n' | sudo apt upgrade | awk '
/be installed|be upgraded/{f=1;next}; /not upgraded|kept back/{f=0}f' | awk '
BEGIN {RS=" ";} {print $0}
' | grep . > apt_upgrade_list

$echo -e 'n' | sudo apt full-upgrade | awk '
/be installed|be upgraded/{f=1;next}; /not upgraded|kept back/{f=0}f' | awk '
BEGIN {RS=" ";} {print $0}
' | grep . > apt_fullupgrade_list

and compare:

 $diff apt_get_dist_list apt_fullupgrade_list | grep -E '<|>'

I get nothing, as expected because apt full-upgrade and apt-get dist-upgrade are meant to behave in the same exact way, but when I compare:

$diff apt_get_upgrade_list apt_upgrade_list | grep -E '<|>'

I get the same output as when comparing apt-get upgrade with apt-get dist-upgrade.

> gir1.2-nm-1.0
> libcpupower2
> linux-kbuild-5.2
> blueman
> linux-cpupower
> linux-headers-amd64
> linux-image-amd64
> pdf-parser

and the only conclusion I can arrive at is that apt upgrade is exactly the same as apt full-upgrade which also makes it the same as apt-get dist-upgrade, which ultimately means that not only is apt upgrade redundant, but what is also more of a concern is that currently apt does not allow for the same behavior as apt-get upgrade.

NetIceCat
  • 2,294

1 Answers1

24

They’re not redundant; there’s an additional subtlety:

  • apt-get upgrade will only upgrade currently-installed packages;
  • apt upgrade will upgrade currently-installed packages and install new packages pulled in by updated dependencies;
  • the various dist-upgrade and full-upgrade variants will upgrade currently-installed packages, install new packages introduced as dependencies, and remove packages which are broken by upgraded packages.

Put another way:

Command Upgrade Install Remove
apt-get upgrade Yes No No
apt upgrade Yes Yes No
apt-get dist-upgrade, apt full-upgrade etc. Yes Yes Yes

In practice, apt upgrade is safer than apt-get upgrade (by default) because it allows updated kernels to be installed automatically when the ABI changes. See apt-get upgrade holds back a kernel update. What are the official instructions for applying updates on Debian 9? for an example.

apt-get upgrade can be told to behave like apt upgrade with the --with-new-pkgs option. This is also configurable using APT configuration files; you can see apt’s specific settings with apt-config dump | grep '^Binary::apt (the setting involved here is APT::Get::Upgrade-Allow-New).

Stephen Kitt
  • 434,908
  • So it is redundant to call apt autoremove after apt dist-upgrade? – Martin Braun Mar 29 '22 at 00:44
  • 1
    No, it isn’t redundant. – Stephen Kitt Mar 29 '22 at 04:31
  • 1
    A little more explanation is no doubt in order: dist-upgrade will ensure that all install packages are upgraded to the latest versions, if possible, and will remove packages if that is required to reach that state. It won’t clean up packages which are no longer necessary. To do that, you need to run autoremove afterwards, or specify --autoremove as an option on dist-upgrade. – Stephen Kitt Mar 29 '22 at 10:02
  • This was helpful, I appreciate your elaboration on this topic. – Martin Braun Mar 29 '22 at 19:23
  • Thank you for this sharp, clear and concise answer. I've been reading about this conundrum for the last 48 hours and you clarified everything for me. – darbehdar Feb 27 '24 at 08:04