How to Add an APT Repository

APT is a free and open source package management system used by many popular Linux distributions, such as Debian and Ubuntu.  APT provides an easy way to install, update, and remove packages for your server.  By default, APT includes repositories for your installation CD and the default online distribution repositories.  If you want access to third-party repositories, you need to add them manually.

In Debian you can easily add APT repositories by editing the sources.list file.  You can usually find this file on most Debian-based distributions at /etc/apt/sources.list.  In it, you will see “deb” lines for each repository.  These lines always follow the same format:

  1. package type
  2. web address
  3. distribution
  4. section

For example, an APT line may look like this:

deb debian unstable

To add a repository to the file, you will need to get the correct APT line from the third-party provider.  In most cases, it must match your distribution and version in order for apt-get to actually install packages from it.  There are exceptions, however, for general repositories that support multiple operating systems.

Add the deb line to the bottom of the file, save the file, and exit your text editor.  Most repositories also have authentication keys that you should install.  Use the following commands to retrieve and install the key:

# gpg –keyserver [name of keyserver] –recv-keys [keyhash]
# gpg –export –armor [keyhash] | apt-key add –

Finally, to complete the process, you must update APT to add the new repository data to your system’s cache.

# apt-get update

You should then be able to download and install new packages from your third-party repository.