How to Add APT Repository on Ubuntu and Debian Systems 2023

How to Add APT Repository on Ubuntu and Debian Systems

Looking to install software from a third-party repository on your Ubuntu or Debian system? The process is simple and can be done in two ways. You can either use the add-apt-repository command or manually add the repository using a text editor.

By default, Ubuntu repositories offer thousands of applications, but sometimes you may need software from a different source. When you use the Ubuntu Software Center or command line utilities like apt or apt-get, the packages are downloaded from one or more apt software repositories, which are network servers or local directories containing deb packages and metadata files readable by the APT tools.

Read on to learn how to add an apt repository on your Ubuntu or Debian system.

Apt Sources

The file that defines the apt software repositories on Ubuntu and other Debian-based distributions is located at /etc/apt/sources.list, or in separate files under the /etc/apt/sources.list.d/ directory.

Repository file names in the /etc/apt/sources.list.d/ directory must end with .list.

The /etc/apt/sources.list file follows a general syntax in the following format:

deb http://repo.tld/ubuntu distro component...
  • The type of the archive is defined in the first line. The archive can be of two types: deb, which indicates that it contains .deb packages, or deb-src, which contains source packages.
  • The second line lists the URL of the repository.
  • The third line specifies the distribution code name, such as beaver or xenial.
  • The last lines indicate the repository components or categories. The default Ubuntu repositories have four components: main, restricted, universe, and multiverse. Third-party repositories typically have only one category.

he structure of files in the /etc/apt/sources.list.d/ directory follows the same format as the standard sources.list file. In order to authenticate downloaded packages, most repositories offer a public key that needs to be imported.

To add or remove a repository, administrative privileges are required, either through a sudo-enabled user or as the root user. Typically, guidelines on how to activate a particular repository are documented in the software’s instructions.

Installing add-apt-repository (add-apt-repository command not found )

The Python script is known as add-apt-repository enables users to include an APT repository to either /etc/apt/sources.list or a distinct file in /etc/apt/sources.list.d. Furthermore, it can remove an already present repository.

In case the add-apt-repository is not present on the system, an error message will indicate that the “add-apt-repository command not found”.

To acquire the add-apt-repository utility, users need to install the software-properties-common package by executing the following commands:

sudo apt update
sudo apt install software-properties-common

Adding Repositories with add-apt-repository

The add-apt-repository command follows the fundamental syntax below:

add-apt-repository [options] repository

The add-apt-repository command can add either a regular repository entry, such as deb http://repo.tld/ubuntu distro component , to the sources.list file or a PPA repository in the ppa:<user>/<ppa-name> format. To view all available options for this command, type man add-apt-repository in your terminal.

By default, on Ubuntu 20.04 and newer versions, the add-apt-repository command will update the package index if the repository public key is imported. The package index is a database that contains records of available packages from the enabled repositories in your system.

Suppose you wish to install MongoDB from their official repositories. In that case, you should first import the repository public key:

sudo apt-key adv --keyserver hkp:// --recv 9DA31620334BD75D9DCB49F368818C72E52529D4

Use the following command to add the MongoDB repository:

sudo add-apt-repository 'deb [arch=amd64] bionic/mongodb-org/4.0 multiverse'

The sources.list file will be updated to include the new repository. Once this is done, you will be able to install any packages from the newly added repository:

sudo apt install mongodb-org

To remove a repository that was previously enabled, utilize the –remove option for any necessary reasons:

sudo add-apt-repository --remove 'deb [arch=amd64] bionic/mongodb-org/4.0 multiverse'

Adding PPA Repositories

The Personal Package Archives (PPA) service permits Ubuntu users to upload source packages, which are then compiled and released through Launchpad as an apt repository.

To include a PPA repository, the add-apt-repository command generates a fresh file within the /etc/apt/sources.list.d/ directory.

As an illustration, to include Jonathon F’s PPA, which offers version 4.x of FFmpeg, the following command would be executed:

sudo add-apt-repository ppa:jonathonf/ffmpeg-4

To enable the repository, simply press Enter when prompted.


Press [ENTER] to continue or Ctrl-c to cancel adding it.

Upon adding the PPA to your system, the repository’s public key will be automatically downloaded and registered. Afterward, you can proceed to install the repository packages by executing the following command:

sudo apt install ffmpeg

By running the apt command, the package along with its dependencies will be installed.

Manually Adding Repositories

To manually organize your sources and exercise greater control, you can modify the /etc/apt/sources.list file and insert the appropriate apt repository line.

To illustrate this process, let’s enable the CouchDB repository and proceed with the software installation. CouchDB is a NoSQL database that is free and open-source, and it’s maintained by the Apache Software Foundation.

To include the repository, use your preferred text editor to access the sources.list file:

sudo nano /etc/apt/sources.list

Add the repository line to the end of the file:

deb bionic main

Instead of manually modifying the sources.list file using a text editor, you may utilize the following command to add the repository line and append it to the file:

echo "deb $(lsb_release -cs) main" | sudo tee -a /etc/apt/sources.list

A different approach would be to generate a fresh repository file within the /etc/apt/sources.list.d/ directory.

In case of manual configuration of a repository, it is essential to import the public repository key to your system manually. This can be accomplished using either wget or curl:

curl -L | sudo apt-key add -

After executing the above command, you should see OK as the output, indicating that the GPG key has been imported successfully and the packages from this repository will be treated as trusted.

However, before proceeding to install packages from the newly added repository, it is necessary to update the package index:

sudo apt update

After updating the package index, you will be able to install packages from the recently added repository:

sudo apt install couchdb


In summary, this article has provided a comprehensive guide on how to add apt repositories in Ubuntu, which can also be applicable to other Debian-based distributions such as Kubuntu, Linux Mint, and Elementary OS. By following the step-by-step instructions, you can easily access a wide range of software packages and updates from third-party repositories, expanding the functionality of your Linux operating system.

If you have any queries or require further clarification, please don’t hesitate to leave a comment below. Our team will be more than happy to assist you in any way possible.



Hey there! My name is Alex and I'm a professional content writer. I'm also lucky enough to be part of an amazing trio team! I absolutely love what I do and I'm passionate about creating content that engages, informs, and entertains. Whether it's writing blog posts, website copy, or social media content, I always strive to deliver high-quality work that exceeds expectations.

We will be happy to hear your thoughts

Leave a reply