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

I know what the purpose of the update command is, and I was just wondering if i must use it before any package installation I perform. What if I have not update for too long and install some critical packages? Also, is there any occasion that there is no need to do that?

share|improve this question

3 Answers 3

up vote 8 down vote accepted

Your copy of Ubuntu has a private copy of the list of packages that are in Ubuntu's repositories. When you install a package, apt-get reads the list and determines the URL of the package to download (which typically contains package version information).

apt-get update updates the package lists. If you don't do it before an installation, apt-get might complain that it cannot find the package in the repository, because it computed the URL based on an old version of the list (which listed an older version of the package).

Of course, apt-get update is necessary after you have changed the repositories, because the system needs to download the list for the new repositories.

It is essential before upgrading the installed packages, because the system cannot know whether the repo has a new version of a package, unless it has an up-to-date copy of the package list.

There is no reason not to run apt-get update before installing a package. However, it is not necessary, if you know that no new version of that package and of its dependencies have been made available on the mirrors since the last apt-get update. A special case of this is when the package lists are up to date, which is after a reasonably short time since the last apt-get update; this means that all packages on the mirror are the same version as they were.

The package list changes whenever a package is upgraded on the mirror. It is impossible to predict how often it changes, in general, without reference to a specific issue or bug report, or without following the development of that Ubuntu release.

share|improve this answer
    
"The package lists are up to date (which is after a reasonably short time since the last apt-get update" - how short of a time? How often are package lists changed? What can change package lists? –  mathguy54 Mar 6 at 17:24
    
@mathguy54 answer updated. In practice, I run apt-get update whenever I get 404 errors ("file not found") while downloading packages. –  ignis Mar 10 at 12:31
    
"Ubuntu has a private copy of the list of packages that are in Ubuntu's repositories" - where is this list? I'd like to read it. Thanks for the great information. –  mathguy54 Mar 10 at 16:13
    
@mathguy54 You can read the files ending in *_Packages under /var/lib/apt/lists/ with a text editor, however one typically does a more advanced search with the package management tools, e.g. apt-cache show/policy/etc. –  ignis Jul 4 at 10:12

You do not absolutly need to use the update command before you install a package, but if you don't you might end up upgrading a package just after you installed it.

Also, keep in mind that you need to update your system regularly. If you don't your computer will be at risk (you won't have the latest security patches).

share|improve this answer

If you've only just added a software repository (PPA or Debian repository), you'll have to run apt-get update to poll the repository and essentially add any packages in it to APT's list of available software. Otherwise, APT won't recognize the name of the package you tell it to install.

When installing new software via the command line, it is a good idea to update the repository information so you don't install software only to discover that it is outdated. This is true of upgrading software as well.

If you use the graphical method of installing or upgrading software, e.g. the Ubuntu Software Center or Update Manager, respectively, these clients will automatically check for the absolute latest versions of packages.

This being said, if you're installing a batch of software and have run an update just minutes or even a few hours before, chances are you'll get the latest version. However, if you're installing the type of software that is updated frequently (such as alpha/beta or bleeding-edge software), you'll want to run an update before fetching anything from that software's repository.

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.