is there a use case for `apt-get install` without `update`?

Every time I see instructions to run apt-get install, it says to run apt-get updatefirst. Same for upgrade and dist-upgrade.

Why doesn't install automatically do update? Is there a case where you don't want that?


Solution 1:

apt-get update updates the lists of available packages and their version numbers.

The use case you are searching for could be: If you want to run apt-get install twice in a short time, you only need to run apt-get update once because the package lists are unlikely to have been changed in the meantime.

Solution 2:

As mentioned in the other answer, apt-get update updates the list of available packages. So, unless the list of available packages has changed, it's simply wasting time and (not much) bandwith.

The reason why you often see apt-get update before apt-get install is twofold:

  • Often this is in the context of adding a PPA or some other package source; in this case, you obviously need to update the list of available packages because the first thing you've done is to add to the list of available packages.
  • During the development period the archives are changing quite rapidly; there can be hundreds of changes to the package lists over the course of a day, so it will often make sense to apt-get update first so you don't try to download a version that's no longer available. Once the distro is released the number of changes drops dramatically - generally down to no more than a couple each week. There's little point in running apt-get update before an install in this case.

Solution 3:

Besides having run sudo apt-get update very recently, there are a few other situations where you might decide not to run it before running sudo apt-get install ...:

  • You are installing software from a local software source that is already configured, such as a CD/DVD or USB flash drive with an Ubuntu ISO burned/written to it.
  • You know you have the package you wish to install cached locally (in /var/cache/apt/archives), either from it being installed before, or having run sudo apt-get --download-only install ..., and you want to install it from there rather than downloading it.

    (Perhaps you want to do something with that version even if it isn't the latest, or your Internet connection is very slow, or you are not connected to the Internet.)

  • You know there is no later version of the package available. For example, the Launchpad page for nano in Ubuntu shows that only the "release" versions are available--nothing is available in "security" or "updates" or "proposed." (In contrast, you can see that firefox in Ubuntu does have such updates.)

  • You want to save time, even at the risk of possibly installing an older package than the recommended version, or even of the installation failing because the package your system wants to install is no longer available, or is listed as having dependencies that are no longer available, or that conflict with some newer software already on your system.

    If your system is configured to check for updates automatically and is connected to the Internet 24/7, this risk might be considered low enough to forego manually running sudo apt-get update most of the time (see RAOF's answer and the comments there).