How To Add Apt Repository In Ubuntu and Debian?

Ubuntu and Debian use the apt repositories in order to download and install packages. Apt repositories provide the *.deb packages with their metadata information. Ubuntu and Debian provide official Apt repositories with a lot of packages. But in some cases 3rd party apt repositories can be used to install different software packages. The add-apt-repository command is used to add new or 3rd party repositories.

“add-apt-repository command not found” Error

The add-apt-repository command is not installed by default. If you try to run this command you will get the “add-apt-repository command not found” error. If you get this error you should install this tool which is described in the following step.

Install add-apt-repository Command

The add-apt-repository command is provided with the package named software-properties-common. So we will install this package like below.

sudo apt install software-properties-common

Add Apt Repository with add-apt-repository Command

The basi syntax of the add-apt-repository is like below.

add-apt-repository OPTION REPOSITORY
  • OPTION is used to provide options to the command. This option is optional.
  • REPOSITORY is the repository URL we want to add. This option is required.

In the following example we will add a repository about the get.deb.net. As repository change is administrative task it requires root privileges which can be provided with the sudo command. Also the add-apt-get can run as a root user.

sudo add-apt-repository "deb http://archive.getdeb.net/ubuntu wily-getdeb games"

Security is important part of today IT. Ass the add-apt-repository command adds 3rd party repositories to install software into the Linux system the packages should be verified by this repository in order to prevent breaches. Adding apt repository can be made secure with the public and private keys where a key server should be specified for a specific repository. The key server is specified with the –keyserver and –recv options by using the apt-key command. The –keyserver is used to specify the key server and –recv is used to specify start of the public key we want to import.

sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 9DA31620334BD75D9DCB49F368818C72E52529D4

Add PPA Repositories

The Apt repositories also expressed as PPA repositories. The PPA repository is a repository that is generally owned personally or by a group of independent developers. The Launchpad provides the PPA repositories. The add-apt-repository command can be also used to add PPA repositories.

sudo add-ppa-repository ppa:libreoffice/ppa

The PPA repositories have the following naming syntax.

ppa:USER/NAME
  • ppa is used to express this is a PPA repository.
  • USER is the PPA username which is created by LaunchPad.
  • NAME is the PPA name where a single user may provide multiple PPA repositories.
See also  Copy From Local To Remote with SCP Command

Add Repository Manually via sources.list Configuration File

The repository information is stored in the /etc/apt/sources.list configuration file. Every line is a repository in this file. The add-apt-repository command actually adds provided repository into this file. We can also manually add repositories in this configuration file. Like add-apt-repository command we will open sources.list file with the root privileges by using sudo command.

sudo nano /etc/apt/sources.list
Add Repository Manually via sources.list Configuration File

We will just add the following line to the end of the file. The # sign at the start of the line makes this line comment and it will not interpreted as repository. Just put following line.

deb http://archive.getdeb.net/ubuntu wily-getdeb games

A repository can be disabled by using # sign by making it comment. As an example the following repository configyration is disable by commenting it.

Disable Repository

Remove Specified Repository with add-apt-repository Command

Even the add-apt-repository command is created to add new repositories it can be also used to remove the existing repository. The -r or –remove option can be used to remove the specified repository. The repository is specified with its URL or PPA. Also like adding a repository removing a repository requires the root privileges which can be provided with the sudo command.

sudo add-apt-repository -r "deb http://archive.getdeb.net/ubuntu wily-getdeb games"

Leave a Comment