What is the use of the various apt commands?

Solution 1:

Let's have some basic idea on how repository is maintained in Ubuntu and in general Linux distribution. Ubuntu and Linux distributions uses repository to provide software, which are installed by installing one or more of the packages.

Some terminology

Software: We would say, a software is a program or a set of programs which satisfy a need or goal. Such as "Cheese" is a software, which is used for taking photos, recording videos etc.

Package: A package is the smallest unit of software, which is distributed by the Ubuntu distribution. A package may be a complete software or a part of a software. A software consists of zero or more packages.

Package-list: Ubuntu or in general Linux distributions use package-list, which contains information about available packages. These lists are stored online, which are retrieved by Package management software such as apt-get, aptitude, synaptic or Ubuntu software center in your computer. After these lists are downloaded in your computer, package management software (such as apt-get) know, what packages are available online in the repository.

Repository: A repository is the name of online storage, which contains packages, package list and package verification information. These sometimes are also referred to as package sources.

sources.list: This file stores information about enabled repositories. This is located in /etc/apt directory in Ubuntu system. You can view the content of that file by going to /etc/apt folder and double-clicking the sources.list file there. Also note that, some repository lines are also stored in files in /etc/apt/sources.list.d directory. The files containing repository line in that directory needs to have extensions .list. apt-get and other package management software recognizes repository lines in that directory too.

Repository-line: Repository-line refers to the format of each (non commented) lines in sources.list file. Also called source line or repo line.

Source package: Don't be confused with package source, which refers to a repository containing packages. Source package is the package containing source codes which can be compiled to get actual binary programs, which then can be executed and hence run.

The correct format of repository source line is

<type of repository>  <location i.e URI>  <dist-name> <components> 

For example, a repo line can be like this one

  deb http://archive.ubuntu.com/ubuntu precise main

Here, it means, the repository is for binary packages, which are hosted in http://archive.ubuntu.com/ubuntu and this repository is for Ubuntu precise (12.04) and this repository contains the main (software which are officially supported by Canonical) component.

  • Type: deb is the type of repository, it indicates it is a binary repository, not a source repository, which has type deb-scr. Binary repository contains compiled packages, as opposed to source repository which contains source packages.

  • Location: http://archive.ubuntu.com/ubuntu location of the repository.

  • Dist-name: precise is the distribution name of Ubuntu release. For Ubuntu 12.04 it is precise, 11.10 is oneiric.

  • Component: main is indicating the component of repository. Ubuntu repository are divided into four parts.

    1. Main - Which contains free and open source software, officially supported
    2. Universe - These softwares are not supported by Canonical, but those are maintained by the community.
    3. Restricted - These softwares are supported by Canonical, but aren't free. These are supported to provide some essential drivers
    4. Multiverse - These are also non-free softwares, and not supported by Canonical.

See this page for more information.

Explanation of the commands

  1. sudo apt-get update

    This command checks if your system has up to date package list and if not retrieves the package list files stored in online repository. For example, if your sources.list file contains lines like this deb http://archive.ubuntu.com/ubuntu precise main, it checks your system whether you have the package list (of binary packages) for main component. If it finds that you don't have the list or your list is outdated, it will fetch the list from the repository.

    If you are really interested to see the package list stored in your Ubuntu system, go to /var/lib/apt/lists directory to see them. The package list are stored there after fetching.

    Note: there can be many method to fetch those list, which are beyond the scope of this answer.

  2. sudo apt-get upgrade

    This command downloads and installs the updated version of packages. This command does not download and install the packages if you have already installed them. Also, it does not remove any packages. So, if an upgrade of a package X requires removal of package Y, this command does not upgrade package X at all.

  3. apt-add-repository

    This command is used to add a repository in your system. Adding a repository means, adding the ability to install packages from a certain online source, not installing all packages from there.

    This command needs the repository source line or PPA links.

    To add a regular repository: use sudo apt-add-repository <repo-line>

    such as sudo apt-add-repository deb http://archive.ubuntu.com/ubuntu precise universe

    To add a PPA repsitory: use sudo apt-add-repository PPA-Name

    such as sudo apt-add-repository ppa:gwibber-daily/ppa

Note 1: Bear in mind that you can use both apt-add-repository or add-apt-repository command.

Note 2: Adding PPA with this command actually checks Launchpad.net site for the existence of that PPA and creates a file in /etc/apt/sources.list.d directory with PPA name containing the standard format of repository line.

From Wikipedia:

Launchpad is a web application and website that allows users to develop and maintain software, particularly free software. Launchpad is developed and maintained by Canonical Ltd.

And it is the same Canonical Ltd, which is official sponsor of the Ubuntu.

Notes on PPA repository: You may have noticed that, if you add a PPA, the repository source line is not copied in /etc/apt/sources.list file. So, where do they go?

Those lines go to a file in /etc/apt/sources.list.d directory and the file is saved with this format: <PPA-name>-<dist-name>.list. (The file name format may not always follow the above rule in that directory for some PPAs)

For example, if you use PPA:gwibber-daily/ppa, a file will be created with the name gwibber-daily-ppa-precise.list which will contain the repository line in standard format. The content of file in my Ubuntu is --

deb http://ppa.launchpad.net/gwibber-daily/ppa/ubuntu precise main
deb-src http://ppa.launchpad.net/gwibber-daily/ppa/ubuntu precise main

You have noticed that, that command added a repo line in standard format. Also, it automatically enabled the repository for source packages. (Note the line beginning with deb-src indicating a repository of source packages)

These conversion from PPA name to repository line is done by apt-add-repository and it is of no surprise because, Launchpad.net is owned by Canonical Ltd, which is also the sponsor of Ubuntu.


  • Apt-get manual
  • What are PPAs and how do I use them?

Solution 2:

A bit of background

For update and install Ubuntu like systems uses a concept called software source or repository.

A repository is collection of libraries, executable.

The libraries, software's inside a repo is maintained using a list file. So when somebody update the list file in server , the user will download the latest list file. This list file indicates which files has update and which are not. Using this you can download only the updated component. No need to get whole software.

Beside Ubuntu official repo, there are many 3rd party developers who distribute there application. Ubuntu provided them a easy way to distribute in Ubuntu. That is called a PPA.

A PPA is also a repo, but maintained by the developer. Ubuntu doesn't take responsibility.

Your questions answer

apt-add-repository your-repository-here is to add a PPA as a source of software for your computer.

apt-get-update is to get the latest source file list (not the software, it downloads only the index) from the all added repo. Like you added some repo in first step. Those software won't be available till you execute them.

sudo apt-get upgrade is to update all available updates for the installed software. It uses the latest list file downloaded as a reference to determine which components needs to be installed .

Solution 3:

Here is the low down:

To compare your current package list with the ones in the repositories, you would run

sudo apt-get update

To upgrade all your installed software packages, you would run

sudo apt-get upgrade

To add repositories to your system (Repositories are servers which contain sets of software packages), you would use

sudo apt-add-repository ppa:<repository-name>

You can do

sudo apt-get update && sudo apt-get upgrade

For complete information on apt-get command see AptGet/Howto