How To Add Apt Repository In Ubuntu 18.04 – When installing packages using the Ubuntu Software Center or using command line utilities such as
apt-get they are downloaded from one or more apt software repositories. The APT repository is a network server or local directory containing deb packages and metadata files that can be read by the APT Tool.
While there are thousands of applications available in the default Ubuntu repositories, sometimes you may need to install software from 3rd party repositories.
In this tutorial, I will show you two ways to add an apt repository on Ubuntu and Debian systems. The first method is to use commands
add-apt-repository and the second is manually adding the repository using a text editor.
On Ubuntu and all linux distro other Debian based, software repositories
apt defined in the file
/etc/apt/sources.list or in a separate file under the directory
Repository file names in the directory
/etc/apt/sources.list.d/ must end with
General syntax of
/etc/apt/sources.list takes the following format:
deb http://repo.tld/ubuntu distro component...
- The entry in the first line determines the archive type. The type of archive can be deb or deb-src. Deb implies that the repository contains packages .deb while deb-src implies a package source.
- The second entry is the repository URL.
- The third entry specifies the distro code name, such as beaver, xenial, and so on.
- The last entry is the repository component or category. The Ubuntu default repository is divided into four components – main, restricted, universe and multiverse. Generally, third party repositories have only one category.
Format for files under directory
/etc/apt/sources.list.d/ the same as for files
sources.list the usual.
Most repositories provide a public key to authenticate downloaded packages which need to be downloaded and imported.
To be able to add or remove repositories, you must be logged in as a user with access rights
root. Read → How to Create a Sudo User and a Sudo Group on Ubuntu.
Usually, instructions on how to activate a specific repository are included in the software documentation.
Install add-apt-repository (command add-apt-repository not found)
add-apt-repository is a Python script that allows you to add the APT repository to
/etc/apt/sources.list or to a separate file in a directory
/etc/apt/sources.list.d. This command can also be used to delete an existing repository.
add-apt-repository not available or not found on your linux system, you will get an error message saying “add-apt-repository command not found”.
add-apt-repository included in the package
software-properties-common. To install it run the following command:
$ sudo apt update
$ sudo apt install software-properties-common
Adding the repository with
The basic syntax of the command
add-apt-repository is as follows:
add-apt-repository [options] repository
Where repositories can be regular repository entries which can be added to files
deb http://repo.tld/ubuntu distro component or PPA repository in
To view all available options from
add-apt-repository command type
man add-apt-repository at your terminal.
By default, on ubuntu 18.04 and above
add-apt-repository will also update the package index if the repository’s public key is imported.
The package index is database which keeps a log of the packages available from the enabled repositories on your system.
Let’s say you want to install MongoDB from their official repository.
First import the repository’s public key:
$ sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 9DA31620334BD75D9DCB49F368818C72E52529D4
Add the MongoDB repository using the command below.
$ sudo add-apt-repository 'deb [arch=amd64] https://repo.mongodb.org/apt/ubuntu bionic/mongodb-org/4.0 multiverse'
The repository will be added to the file
You can now install one of the packages from the newly activated repository:
$ sudo apt install mongodb-org
If for any reason you wish to delete the repository that was previously enabled then use the option
$ sudo add-apt-repository --remove 'deb [arch=amd64] https://repo.mongodb.org/apt/ubuntu bionic/mongodb-org/4.0 multiverse'
Added PPA Repository
Personal Package Archives (PPA) is a service that allows users to upload Ubuntu source packages created and published with Launchpad as a proper repository.
When adding the PPA repository, command
add-apt-repository create a new file under the directory
For example, to add PPA Jonathon F providing FFmpeg version 4.x you would run:
$ sudo add-apt-repository ppa:jonathonf/ffmpeg-4
When prompted press Enter and a repository will be activated.
Output Press [ENTER] to continue or Ctrl-c to cancel adding it.
The PPA repository public key will be automatically downloaded and registered.
Once the PPA has been added to your system you can install the repository packages:
$ sudo apt install ffmpeg
apt will install the package and all of its dependencies.
Adding the Repository Manually
If you want to have more control over how your sources are organized, you can edit the
/etc/apt/sources.list manually and add the apt repository line to the file.
For demonstration, I will activate the CouchDB repository and install the software. CouchDB is a free, open source tolerant NoSQL database maintained by the Apache Software Foundation.
To add a repository, open the file
sources.list with your text editor:
$ sudo nano /etc/apt/sources.list
Add the repository line to the end of the file:
$ deb https://apache.bintray.com/couchdb-deb bionic main
Instead of editing the file with a text editor, you can use the following command to add a repository line to the file
$ echo "deb https://apache.bintray.com/couchdb-deb $(lsb_release -cs) main" | sudo tee -a /etc/apt/sources.list
$ (lsb_release -cs) will print the Ubuntu codename. For example, if you have Ubuntu version 18.04 the command will print
Another option is to create a new repository file under the directory
When configuring the repository manually, you will also need to manually import the public repository keys onto your system. To do that use
$ curl -L https://couchdb.apache.org/repo/bintray-pubkey.asc | sudo apt-key add -
The command above should display OK which means that the GPG key has been successfully imported and packages from this repository will be considered trusted.
Before installing packages from the newly added repository, you must update the packages index:
$ sudo apt update
Once the packages index has been updated, you can install packages from the newly added repository:
$ sudo apt install couchdb
I have shown you how to add the apt repository in Ubuntu. The same instructions apply for Debian-based Linux distributions, including Kubuntu, Linux Mint and Elementary OS.