An APT repository is a local directory or network server which holds deb packages and metadata files, those are readable by the APT tools. This tutorial describes two methods to add Apt repository on your Ubuntu & Debian systems. The first method uses the
add-apt-repository command to configure the repository and second is to
manually add the repository.
Adding Repositories with add-apt-repository
To add or remove a repository you need be logged in as root or user with sudo privileges.
Following is the basic syntax of the
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
To list all available options of the
add-apt-repository command, in your terminal type
Ubuntu 18.04 and newer the
add-apt-repository will also update the package index if the repository public key is imported. In your system the package index is a set of records of available packages from repositories which are enable.
For instance, you want to install VS Code from their official repositories.
First import the repository public key using wget or curl:
wget -q https://packages.microsoft.com/keys/microsoft.asc -O- | sudo apt-key add -
Run the below command to add VS Code repository:
sudo add-apt-repository "deb [arch=amd64] https://packages.microsoft.com/repos/vscode stable main"
The repository will be added to
At this points you can install any of the packages from the newly enabled repository:
sudo apt install code
Adding PPA Repositories
PPA, or Personal Package Archives is a service to upload Ubuntu source packages that are built and published with Launchpad as an apt repository. The add-apt-repository command creates a new file under the
/etc/apt/sources.list.d/ directory when adding a PPA repository.
For example, to add
LibreOffice you would run:
sudo add-apt-repository ppa:libreoffice/ppa
On prompt hit
Enter to enable repository.
Once the PPA is added to your system you can install the repository packages:
sudo apt install libreoffice
It will install the package and all its dependencies.
Manually Adding Repositories
You can add the apt repository line manually by editing the
sources.list file with your text editor to add the repository:
sudo nano /etc/apt/sources.list
For example, to enable VS Code repository manually, add the following line at the end of file:
deb https://packages.microsoft.com/repos/vscode stable main
You can add this line to file without editing file using command. To append the repository line to the
sources.list file run below command:
echo "deb https://packages.microsoft.com/repos/vscode stable main" > /etc/apt/sources.list
You must update package index before installing the packages from newly added repositories:
sudo apt update
Now you can install packages from the newly added repository:
sudo apt install code
We have shown you how to add apt repositories in Ubuntu.
Feel free to leave a comment if you have any questions.
Leave a Reply