Using apt - Updating

Suppose a new package is added to the software repository. Then you will not be able to download it because the package index on your PC does not list that package. So you will have to update your package index periodically.

sudo apt-get update

In your package index, apart from storing the names of available packages, apt also stores the version-number of those packages. For eg, The latest version of codeblocks available from Ubuntu 15.10 repositories is 13.12.

The package index also stores the version number of programs installed on your PC. Whenever a newer version of a software comes out, the software repositories get updated. As a result, you will have to update your package index using sudo apt-get update.

So the software repositories have a newer version and your package index also knows that version. The thing which is left to be done is actually updating the installed program on your PC.

sudo apt-get upgrade

When you run this command, the package manager will check whether there are installed packages whose versions are lower than the versions available in the software repository. It will then download the newer versions of all such packages, remove the old packages and install the new packages.

When you install a Linux OS, a lot of packages come pre-installed. But consider the example of Ubuntu 15.04. It was released in late April 2015. If you install Ubuntu 15.04 now, the pre-installed packages will be around 6 months old. It is likely that many of these packages have updated versions available in their repositories. Hence whenever you install a new OS, you must do

sudo apt-get update
sudo apt-get dist-upgrade

dist-upgrade is like upgrade, but there are minor differences. Those differences will be discussed later.

You can also upgrade packages using Software Updater, a GUI program in Ubuntu. However, terminal has its own merits which will be discussed later.

Both Ubuntu Software Center and Software Updater actually use apt-get as backend. They are just graphical wrappers around apt-get.

Ubuntu comes with a feature that it automatically does apt-get update periodically in the background, so you don’t have to do it yourself. As soon as this background apt-get update finishes, Software Updater shows you (in a GUI window) the list of packages which need to be upgraded. Then you can either click on the install button in this window or you can sudo apt-get upgrade from the terminal.