Add APT Repository in Linux Ubuntu and Debian

How to Add APT Repository in Linux Ubuntu and Debian?

Installing programs on Linux is only possible via repositories. So, learning different methods to Add APT Repository in Linux is essential. Just join us with this article to review all you need to know. An APT repository is a local directory or a network server that houses deb packages and metadata files that the APT tools can read. Each Linux distribution has some official repositories that house supported stable software.

Regardless of your preferred distribution, the need to install software from a third-party repository may arise occasionally. So, after buying Linux VPS you might face an error from the package manager that says your required package does not exist in the official software repositories. This is when you need to add the third-party repository to your system manually to download it.

An Intro to Linux APT Repository

Software packages are kept and can be downloaded from a package repository, or repo for short. The metadata required by Linux package managers to access the packages in the repository and their dependencies is typically contained in it, which is organized in a unique directory tree. Linux administrators may automatically install and upgrade packages from a configured repo using package managers like APT. They also have tools for software update checking and dependency resolution. Additionally, all package managers, if not the majority, allow for the removal of outdated packages.

Packages are fetched by the APT package management from a number of repositories. A repository might be automatic or simple, binary or source-based. It may also take place offline or online. A repository may also be third-party or official (managed by Debian, Ubuntu, or Canonical).

The Advanced Package Tool (APT) is used by Debian-based distributions, such as Ubuntu, to install and update packages. On your Debian-based Linux installation, the /etc/apt/sources.list file contains information on software repositories.

$ ls /etc/apt/sources.list.d/

Even though you can manually enter repository information into the file, it can get tedious very quickly. In the following of this guide, you will learn a better way to add repository in Linux. Before that, let’s get familiar with the basic syntax of each line in a repository:

deb  URI  distribution component1  component2 … componentN


deb-src  URI  distribution   component1  component2 … componentN

The root of the repository’s URI, the distribution, and one or more components are listed after the first argument, which indicates the archive type (deb for binary files, or deb-src for source files).

APT Repositories Types

APT repositories are divided into two types: Automatic and non-automatic. Typically, software developers or maintainers will offer a way for you to manually or automatically add the appropriate repository so that you can install their package(s) on your Linux system.

Automatic Repository:

You must specify one distribution and one or more components in order to define an automated repository, and the distribution cannot terminate in a slash.

These are some examples of automatic repo definitions:

deb  stable  non-free
deb  pgadmin4  main
deb stable-focal main

Non-automatic repository:

This repository is also known as trivial APT Repositories. The distribution defines the relative path to the index files for non-automatic repositories, and it must terminate with a slash. Furthermore, no components may be mentioned.

Here are some of its examples:

deb bullseye-cran40/
deb file:///home/operavps/rep-exact  binary/

The local package index, a database of readily available packages from the repositories listed in the /etc/apt/sources.list file and files under the /etc/apt/sources.list.d directory, is an essential component of APT. The package index files are located in the location /var/lib/apt/lists/.

You must always refresh the local package index before installing or updating packages after making changes to the repo parameters.

$ sudo apt update


$ sudo apt-get update

Methods to Add APT Repository in Linux Ubuntu and Debian

This tutorial covers two different ways to Add Repository in Linux. In the end, you can use any one of the explained methods to Add a Package Repository in Ubuntu and Debian. Let’s see what these two are:

Method 1. Add Repository on Ubuntu and Debian Manually

As the first method to add repository in Linux Ubuntu and Debian, adding manually is explained. To do this, you need to create the repo file under the /etc/apt/sources.list.d directory. You are not recommended to add all repositories in the /etc/apt/sources.list file.

Let’s see how you can add the R software environment packages repository by checking the below examples:

$ sudo vim /etc/apt/sources.list.d/r-packages.list

Now, copy and paste the repo configuration into the file and make sure that the parameters, such as the URI, distribution, and components, match what is specified in the repository:

deb  focal-cran40/

Using the wget command, add the repository key:

$ wget -qO- | sudo tee -a /etc/apt/trusted.gpg.d/cran_ubuntu_key.asc

As an alternative, you can add the repository using the echo command and tee as follows:

$ echo "deb  focal-cran40/" | sudo tee /etc/apt/sources.list.d/r-packages.list
$ wget -qO- | sudo tee -a /etc/apt/trusted.gpg.d/cran_ubuntu_key.asc

At this point, you are ready to install a package from the repository. Before that, run the commands below to update the local package index with the latest changes made in the repositories.

$ sudo apt update
$ sudo apt install --no-install-recommends r-base

Then, you can also disable an apt repository if needed by running the following command in the repository configuration file as displayed in the screenshot that follows.

Disable APT Repository

Method 2. Add Repository in Linux Using apt-add-repository Command

The second method to add repository in Linux ubuntu uses Command Line. A repository can be added to the /etc/apt/sources.list directory or file using the add-apt-repository command-line tool. The -r flag can be used to delete an existing repository. If your system does not already have the add-apt-repository tool, you can install the software-properties-common package to get it:

$ sudo apt update
$ sudo apt install software-properties-common

Also, you can use the below first command to add the repository and run the second one to retrieve the repository key and save it to the designated file:

$ sudo add-apt-repository "deb $(lsb_release -cs)-cran40/"
$ wget -qO- | sudo tee -a /etc/apt/trusted.gpg.d/cran_ubuntu_key.asc

Note: As you guess, when you face the “Repository already exists” message, it is because you are trying to add a repository that already exists.

As the final step, again you need to update the apt package index and install a package from the repository

$ sudo apt update
$ sudo apt install --no-install-recommends r-base

How to Add PPAs in Linux

Previously, you learned What Is PPA and How to Use It to Install Software in Ubuntu. Personal Package Archives (PPAs) are software repositories for using Launchpad to publish user-contributed software packages. You can add PPAs via two different methods: Command Line and GUI. Let’s go through this section to learn more.

1. Add PPAs from Command Line

For example, you can run the following commands to add the Shutter screenshot tool’s official PPA.

$ sudo add-apt-repository ppa:shutter/ppa
$ sudo apt-get update
$ sudo apt install shutter

Also, you can remove all installed PPA repository by running the command below:

$ sudo add-apt-repository -r "deb $(lsb_release -cs)-cran40/"

2. Add PPAs from GUI

A GUI program can be used to add a repo to your system as well. Recently, you learned to Use APT Package Manager in Ubuntu. Open the Software & Updates menu on Ubuntu by using the Activities search bar. Then select the Other Software tab, which is seen in the following screenshot as being highlighted. Next, select Add, enter the repo configuration, and then adhere to the instructions.

Software & Updates Window

After that, select the Additional Repositories tab and press the Add button.

Additional Repositories

Add the repository and hit OK in the pop-up window.

Add APT Repository

At the bottom of the window, a notice will appear after the repo has been successfully added. Click OK to continue.

Updating APT Cache

That’s it. all you need to add APT repository in Linux Ubuntu and Debian was explained. Select your preferred method and go for it.


Ubuntu has a tool called Launchpad that lets programmers build their own repositories. End users, or you, can add the PPA repository to their sources.list so that when they update their system, it will be aware of the new software's existence and allow them to install it using the regular sudo apt install command.

If you simply search the web for the PPA name, such as ppa:dr-akulavich/lighttable, the Launchpad website, the official PPA hosting platform, should come up as the first result. Alternatively, you can visit Launchpad and perform a straight search for the necessary PPA there.


In this article, you learned How to Add APT Repository in Ubuntu and Debian. Two different methods were explained for both Command Line lovers and users who prefer to do the actions manually. You can quickly obtain updated software versions or software that is not offered through the official Ubuntu repository with PPA. Any Debian-based distribution, such as Kubuntu, Linux Mint, and Elementary OS, can use the same ways explained.

Now you know you can use the sudo add-apt-repository <PPA_info> command when you need to add the PPA repository to the list and run the sudo apt-get update command to update the list of the packages that can be installed on your system. Also, you saw that the sudo apt-get install <package_in_PPA> command installs the package.

If you follow anyone the methods properly then you can smoothly Add APT Repository in Linux Ubuntu and Debian without any errors but do not hesitate to contact us if you encounter any problems. Our technical support team will try their best to solve your problems. If you know other ways to achieve the purpose of this article subject, then the comment section is all yours.

Related Article : What is Debian OS

Leave a Reply

Your email address will not be published. Required fields are marked.