Repositories in Ubuntu are defined as the containers in which different software programs are kept. These repositories make it easier for us to install new software whenever we need it. These programs are developed while keeping in mind the specifications and security requirements of each version of Ubuntu. That is why it is very safe to install software via Ubuntu repositories.

Ubuntu provides us with four basic types of repositories which are listed below:

  • Main: This repository contains free and open-source software which is supported by Canonical.
  • Restricted: This repository is composed of proprietary drivers for devices. 100% support cannot be provided for the software of this repository.
  • Universe: This repository also contains free and open-source software that is maintained by the Community.
  • Multiverse: This repository is composed of software which is not free and requires a license to access it. Usually, the software under this repository is not supported at all, and users are expected to use them at their own risk.

Different commands are associated with the repositories in Ubuntu. In this article, we are going to learn about the “add-apt-repository” command in Ubuntu 20.04.

Explanation of “add-apt-repository” Command:

In this section, we will try to learn the basics of the “add-apt-repository” command in Ubuntu 20.04.

Purpose of “add-apt-repository” Command:

Following are the three main purposes of the “add-apt-repository” command in Ubuntu 20.04:

  1. Adding a new repository to the /etc/apt/sources.list
  2. Adding a new repository to the /etc/apt/sources.list.d
  3. Removing an already existing repository

It means that this command can either be used to add a new repository to one of the two locations specified above or it can delete an already existing repository.

Syntax of the Command:

The general syntax of this command is as follows:

add-apt-repository “options” “repository”

Here, “repository” refers to the new repository that you want to add or the existing repository that you want to remove whereas “options” are the different parameters that can be used in conjunction with this command. These options are discussed in the following section.

Options used with the “add-apt-repository” command:

Note: These options are slightly different for each version of Ubuntu. Here, we are only going to talk about the options that are supported by Ubuntu 20.04 for this command.

Seven basic options are supported by this command in Ubuntu 20.04. These options are explained below:

  • “-h”: This option refers to “help”. It is used for showing help messages and exiting. The syntax of this option is as follows: add-apt-repository –h “repository”
  • “-m”: This option stands for “massive debug”. It is used for printing a large amount of debugging information onto your command line. The syntax of this option is as follows: add-apt-repository –m “repository”
  • “-r”: This option refers to “remove”. It is used for removing the specified repository. The syntax of this option is as follows: add-apt-repository –r “repository”
  • “-y”: This option stands for “yes”. It is used for assuming yes to all the generated queries. The syntax of this option is as follows: add-apt-repository –y “repository”
  • “-k”: This option refers to “keyserver”. It is used for enabling the use of a custom keyserver URL rather than using the default one. The syntax of this option is as follows: add-apt-repository –k “repository”
  • “-s”: This option stands for “enable-source”. It is used for allowing the download of the source packages from the specified repository. The syntax of this command is as follows: add-apt-repository –s “repository”
  • “-u”: This option refers to “update”. It is used for updating a repository after successfully adding it. By making use of this option, you no longer need to use the apt-get update command to update your packages and repositories. The syntax of this option is as follows: add-apt-repository –u “repository”

These seven options can be used with this command as needed. All you have to do is to replace “repository” with the name of that repository on which you want the specified operation to be performed.

Conclusion:

In this article, we have learned the basic usage of the “add-apt-repository” command in Ubuntu 20.04. We also talked about the four main types of repositories in Ubuntu. There was a brief discussion about the different options that can be used with the “add-apt-repository” command in Ubuntu 20.04. By making use of these different options along with this command, you can conveniently add or remove any desired repository while using this operating system. You only need to take care of the correct syntax as is explained in this article.

About the author

“add-apt-repository” Command in Ubuntu 20.04 ubuntu

Karim Buzdar

Karim Buzdar holds a degree in telecommunication engineering and holds several sysadmin certifications. As an IT engineer and technical author, he writes for various web sites. You can reach Karim on LinkedIn.