How to add Apt Repository in Ubuntu system

How to add Apt Repository in Ubuntu system

In this article we are going to show you that how to add Apt Repository in your Ubuntu system.

An APT repository is a local directory or network server or collection of deb packages with metadata that is readable by the APT tools.

With help of  APT repository, you can perform package install, removal, upgrade, and other operations on individual packages or groups of packages.

To add or remove a repository, you must need to logged in as root or user with sudo privileges.


Installing add-apt-repository

When add-apt-repository is not available in your Ubuntu system then you will get an error message saying “add-apt-repository command not found”.

To fix this error, install add-apt-repository by running command below:

sudo apt update
sudo apt install software-properties-common

Adding Repositories with add-apt-repository

The basic syntax of the add-apt-repository command is show as below:

add-apt-repository [options] repository

There are two type of repository, one is PPA repository that is in ppa:[user]/[ppa-name] format or a regular repository entry that can be added to the sources.list file like deb http://repo.tld/ubuntu distro component.

In ubuntu 18.04 and newer the add-apt-repository will also update the package index if the repository public key is imported. Package index is a database or set of records of available packages from repositories which are enable in your Ubuntu system.

For an example, if you want to install Visual Studio Code from their official repositories then first import the repository public key using wget or curl command:

wget -q https://packages.microsoft.com/keys/microsoft.asc -O- | sudo apt-key add -

After that, run the command below to add Visual Studio Code  repository:

sudo add-apt-repository "deb [arch=amd64] https://packages.microsoft.com/repos/vscode stable main"

The Visual Studio Code repository will be added to sources.list file.

Now run the command below to install Visual Studio Code:

sudo apt install code

Adding PPA Repositories

PPA (Personal Package Archives) is a service that is used to upload Ubuntu source packages that are built and published with Launchpad as an apt repository.

When you are add a PPA repository in your Ubuntu system then the add-apt-repository command creates a new file under the /etc/apt/sources.list.d/ directory.

For an example, if you want to add LibreOffice PPA repository then run the command below:

sudo add-apt-repository ppa:libreoffice/ppa

When prompted, press Enter to enable repository.

After add the PPA, you can install the repository packages by running below command:

sudo apt install libreoffice

Manually Adding Repositories

If you want to add a repository manually for more control then you can manually edit the /etc/apt/sources.list file and add the apt repository line to the file.

To add the repository, open the sources.list file with your text editor :

sudo nano /etc/apt/sources.list

For an example, if you want enable Visual Studio Code repository manually, add the following line at the end of sources.list file:

deb https://packages.microsoft.com/repos/vscode stable main

You can also add the above line in the sources.list file using command below:

echo "deb https://packages.microsoft.com/repos/vscode stable main" > /etc/apt/sources.list

You will need to update the package index before installing the packages from the newly added repository:

sudo apt update

Now you can install the packages by running below command:

sudo apt install code

That’s all

If you face any error and issue in above steps , please use comment box below to report.

If our tutorials helped you, please consider buying us a coffee. We appreciate your support!

Thank you for your support.

Leave a Comment

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Scroll to Top