Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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?

share|improve this question

3 Answers 3

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.

share|improve this answer

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.
share|improve this answer
    
As mentioned in Erik Sjölund's answer, apt-get update doesn't just update the list of what packages are available from where, but also what versions are available. This changes whenever an update is released, and in practical use, getting information about new versions of old packages is the primary benefit of apt-get update. Even when a release is stable, important updates are released for it, including updates for critical security vulnerabilities. This is hardly a waste of time. –  Eliah Kagan Jul 19 '12 at 4:59
    
It's not a waste of time to run periodically - and, indeed, by default it is run automatically every day. It would be a waste of time to run before every apt-get invocation, which was what the question was asking. –  RAOF Jul 20 '12 at 11:31
    
Many computers used as workstations are not connected to the Internet for all or even most of the time they are running, or are configured not to check for updates automatically. Many server systems are configured not to do so either (and there, software is rarely installed using graphical tools that automatically update first). These are the reasons most authors recommend running apt-get update before apt-get install/apt-get upgrade in general (though indeed not when you have just run apt-get update). –  Eliah Kagan Jul 20 '12 at 15:27

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).

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.