540

I was wondering why upgrade sometimes doesn't want to upgrade certain parts of the system, while dist-upgrade does. Here's an example after running apt-get upgrade:

apt-get upgrade:

rimmer@rimmer-Lenovo-IdeaPad-S10-2:~$ sudo apt-get upgrade
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following packages have been kept back:
  linux-generic linux-headers-generic linux-image-generic
0 upgraded, 0 newly installed, 0 to remove and 3 not upgraded.

versus apt-get dist-upgrade:

rimmer@rimmer-Lenovo-IdeaPad-S10-2:~$ sudo apt-get dist-upgrade
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Calculating upgrade... Done
The following NEW packages will be installed:
  linux-headers-3.0.0-13 linux-headers-3.0.0-13-generic
  linux-image-3.0.0-13-generic
The following packages will be upgraded:
  linux-generic linux-headers-generic linux-image-generic
3 upgraded, 3 newly installed, 0 to remove and 0 not upgraded.
Need to get 48.5 MB of archives.
After this operation, 215 MB of additional disk space will be used.
Do you want to continue [Y/n]?

In other words, why can't this be performed by upgrade?

0

6 Answers 6

435

From apt-get manual:

upgrade
   upgrade is used to install the newest versions of all packages
   currently installed on the system from the sources enumerated in
   /etc/apt/sources.list. Packages currently installed with new
   versions available are retrieved and upgraded; under no
   circumstances are currently installed packages removed, or packages
   not already installed retrieved and installed. New versions of
   currently installed packages that cannot be upgraded without
   changing the install status of another package will be left at
   their current version. An update must be performed first so that
   apt-get knows that new versions of packages are available.

dist-upgrade
   dist-upgrade in addition to performing the function of upgrade,
   also intelligently handles changing dependencies with new versions
   of packages; apt-get has a "smart" conflict resolution system, and
   it will attempt to upgrade the most important packages at the
   expense of less important ones if necessary. So, dist-upgrade
   command may remove some packages. The /etc/apt/sources.list file
   contains a list of locations from which to retrieve desired package
   files. See also apt_preferences(5) for a mechanism for overriding
   the general settings for individual packages.

And with the newer apt tool available from 14.04 onwards:

full-upgrade
   full-upgrade performs the function of upgrade but may also remove
   installed packages if that is required in order to resolve a
   package conflict.

In your particular case, I see, for example, that linux-headers is a virtual package that is provided by both linux-headers-3.0.0-12 and linux-headers-3.0.0-13 and that sounds like the kind of package installation and removal handled by dist-upgrade, but not by upgrade.

9
  • 8
    I don't see full-upgrade as an option to apt-get under 14.04.1. May 16, 2015 at 2:34
  • 1
    I didn't knew about apt either but it seems to be a completely diffrent command according to the man page he linked
    – BlueWizard
    Oct 20, 2015 at 20:37
  • 29
    @nobar You don't see because it is an option of apt and not of apt-get... :-) Try man apt.
    – Hastur
    Oct 29, 2015 at 9:47
  • Okay, I searched and the earliest link I found is for Ubuntu 15.10 (which came out end of 2014 which seams reasonable with Jessie testing) manpages.ubuntu.com/manpages/wily/en/man8/apt.8.html
    – Z boson
    Jan 24, 2017 at 15:09
  • 7
    @Zboson Yeah, and 14.04 came out not in 2011, but in April 2014... see the pattern?
    – tgies
    May 18, 2017 at 21:25
183

apt-get upgrade is restricted to the case where packages are to be replaced by newer versions, but no package needs to be added or removed. A new version of Firefox, for instance, should be installable with apt-get upgrade.

However apt-get upgrade will refuse to work when there are additions or removals required by the updated versions. For example, when you have kernel linux-image-3.2.0-10-generic installed and linux-image-3.2.0-11-generic appears, the linux-image-generic package gets updated to depend on the newer version. In order to install the new kernel, you need to run apt-get dist-upgrade.

Notice how an apt-get upgrade will say that the kernel packages have been held back. That's the cue for using apt-get dist-upgrade.

2
  • 5
    Perfect! :D Two more questions... what is used by the graphical update manager in Ubuntu? What is the recommended one?
    – THpubs
    Jan 29, 2012 at 1:46
  • 19
    The graphical utility, update-manager, does not use apt-get directly; instead it works with a backend called aptdaemon. The standard abilities of update-manager are a mix of the upgrade and dist-upgrade modes of apt-get: it can add but not remove packages - it invokes the "Partial upgrade" tool when removals are required. When using the command line, use apt-get upgrade. If you see it reports that packages have been "held back", run apt-get dist-upgrade to pick up the remaining updates.
    – pablomme
    Jan 29, 2012 at 2:10
42

Basically upgrade will only upgrade existing packages from one version to another. It will not install or remove packages, even if doing so is required to upgrade others. In the case of kernel updates, upgrading the linux-generic package requires installing the new linux-3.0.0-13-generic package, and since upgrade refuses to install or remove packages, it refuses to upgrade linux-generic.

Sometimes various incompatibilities between packages will require some packages to be removed in order to upgrade others, and that will also require dist-upgrade. Kernel updates will always require dist-upgrade because of how they are handled. Rather than have a kernel package that gets updated, an entirely new kernel package is created each time, and the kernel metapackage is updated to depend on the new kernel package instead of the old. This was done so that you keep the old kernel versions around so that in case there is a problem with booting the new kernel, you can choose the old one from the boot menu and recover.

1
  • 2
    Best gist. Still, how to keep a certain package? Nov 15, 2013 at 17:06
15

The apt-get upgrade command will normally only install updates (or fixes) to currently installed packages. Typically a new release of Mozilla Firefox, for instance, would be installed with this command.

However apt-get upgrade will NOT generally install new releases, where major changes (including removal of packages or GRUB update is required). For example, when a new Linux kernel (linux-image-3.x.x-xx-generic, etc.) is available, the package will not get installed.

In order to install the new kernel, you will need to run apt-get dist-upgrade. You will be notified when you run apt-get upgrade, as it will say that certain packages have been held back. That's your cue to use: apt-get dist-upgrade.

6
  • 14
    This is misleading. dist-upgrade will not upgrade to a new release unless sources.list has been modified accordingly (and even then, that's not a supported way to upgrade in Ubuntu). When a new kernel is installed with dist-upgrade, that's not a new release of Ubuntu. It's just a new package. Furthermore, the claim "or GRUB update is required" is false. sudo apt-get upgrade is perfectly capable of upgrading packages in a situation where GRUB must be updated, so long as no packages are removed and new packages are installed. update-grub is run automatically, as always. Apr 13, 2013 at 2:11
  • 3
    You should write your own answer, as that add no clarity to mine.
    – david6
    Apr 13, 2013 at 6:13
  • 3
    Besides what Eliah mentioned, the essential point is that apt-get upgrade will not remove or add packages. If a fix to a package requires a new package, the update will be held back. pablomme's answer, which you revised to be less accurate, is better and I'd advise readers to go to that one. May 24, 2013 at 3:19
  • 2
    Correction: apt-get upgrade will never install or remove any packages. Kernel upgrades are packaged as new packages and as a result, apt-get upgrade will never upgrade the kernel. The fact that kernel upgrade does "major" changes such as GRUB configuration is not the reason for the difference between upgrade and dist-upgrade. Sep 19, 2016 at 6:07
  • And what about apt? Apr 18, 2023 at 0:34
10

Short answer those who want the exact point

apt-get update

  • The update command updates the package list with the latest available versions
  • It won't upgrade the installed packages just update the package list with a new version
  • To upgrade need to run the upgrade command

apt-get upgrade

  • To update the already installed packages to the latest available version
  • It will upgrade only the installed packages that already available to the latest version version
  • If the dependencies are missed the current version will be kept without any upgrade

apt-get dist-upgrade

  • To update the already installed packages to the latest available version with required dependencies
  • It will automatically install the required additional packages and dependencies and also removes the already installed packages to make the clear upgrade

apt-get full-upgrade

  • full-upgrade performs the upgrade function but may also remove installed packages if required to resolve a package conflict.

apt-get do-release-upgrade

  • It can upgrade the release version of ubuntu for example if you want to upgrade ubuntu 18.04 to 20.04 we can run do-release-upgrade
  • To use this command, the system must first be fully upgraded. To do that, you should first run sudo apt-get upgrade, followed by sudo apt-get dist-upgrade

ref:https://linuxhint.com/apt_get_upgrade_dist_upgrade/#:~:text=Unlike%20apt%2Dget%20upgrade%20command,sudo%20apt%2Dget%20dist%2Dupgrade

5
  • This is a good quick guide but it'll be even more useful if you can add a reference or two of where did you find this
    – Felipe
    Aug 30, 2022 at 20:57
  • Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.
    – Community Bot
    Aug 30, 2022 at 20:57
  • Guys chill..!!in this answer, 80 % of the words are my own from my understanding and I didn't find these answers in a single link. These are my notes for my understanding. anyway will attach link which i can remember where i referred Aug 31, 2022 at 5:34
  • It's nice answer @jayaprakash, It's not apt-get do-release-upgrade instead sudo do-release-upgrade.
    – minoblue
    Feb 2, 2023 at 1:27
  • You are missing the new apt commands (which is not the same as apt-get). apt upgrade also allows installing new packages actually. Just saying... Apr 18, 2023 at 0:32
2

Your best option is:

apt full-upgrade

-which auto-handles the dependencies when upgrading packages; whereas:

apt upgrade

-does NOT auto-handle dependencies when upgrading packages.

1
  • Are you sure? You are correct if the command would be apt-get, since indeed apt-get upgrade will not resolve and install new packages. However running apt upgrade will install new packages and update existing packages as well just fine. Apr 18, 2023 at 0:33

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .