How to Add Apt Repository Ubuntu 18:04 – When installing the packages using the Ubuntu Software Center or using command line utilities such
apt-getsuch packages downloaded from one or more software repositories apt. APT repository is a network server or local directory containing the deb packages and metadata files that can be read by APT Tool.
Although there are thousands of applications available in the default Ubuntu repositories, sometimes you may need to install software from a 3rd party repository.
In this tutorial, I’ll show you two ways to add the repository apt in Ubuntu and Debian systems. The first method is to use the command
add-apt-repositoryand the second is to manually add the repository using a text editor.
Apt Source Add Apt Repository in Ubuntu
On Ubuntu and all Linux distributions based on Debian other software repository
aptdefined in the file
/etc/apt/sources.listor in separate files under a directory
The names of the repository files in the directory
/etc/apt/sources.list.d/must end with
The general syntax of the file
/etc/apt/sources.listtake the following format:
deb http://repo.tld/ubuntu distro component...
- Entries in the first line determines the type of archive. Archive type can be either deb or deb-src . Deb implies that the repository containing the package .deb while deb-src implies source package.
- The second entry is the URL of the repository.
- The third entry specifies the name of the code distributions, such as beaver, Xenial, and so on.
- The last entry is the component or category repository. The default Ubuntu repository is divided into four components – main, restricted, universe and multiverse. Generally, the third-party repository has only one category.
The format for files under the directory
/etc/apt/sources.list.d/together with the file for
Most repository provides the public key to authenticate the downloaded package that needs to be downloaded and imported.
To be able to add or remove a repository, you must be logged in as a user with access rights
root. Read → How to Create User Sudo and Sudo Group in Ubuntu .
Typically, instructions on how to enable a specific repository included in the software documentation.
Install the add-apt-repository (command add-apt-repository can not be found)
add-apt-repository is a Python script that allows you to add to the APT repository
/etc/apt/sources.listor to a separate file in the directory
/etc/apt/sources.list.d. This command can also be used to remove the existing repository.
add-apt-repositorynot available or can not be found on your Linux system, you’ll get an error message that says “add-apt-repository command not found”.
add-apt-repositoryare included in the package
software-properties-common. To install it run the following command:
$ sudo apt update
$ sudo apt install software-properties-common
Adding repository with
The basic syntax of the command
add-apt-repositoryis as follows:
add-apt-repository [options] repository
Where the repository can be a regular repository entries that can be added to the file
deb http://repo.tld/ubuntu distro componentor PPA repository format
To see all available options of
add-apt-repositorythe type of command
man add-apt-repositoryin your terminal.
By default, at 18:04 ubuntu newer and
add-apt-repositorywill also update the index if the public key repository packages imported.
Package index is a database that keeps track of available packages from the repositories that are enabled on your system.
Say you want to install MongoDB from their official repository.
First import a public key repository:
$ sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 9DA31620334BD75D9DCB49F368818C72E52529D4
Add repository MongoDB using the commands below.
$ sudo add-apt-repository 'deb [arch=amd64] https://repo.mongodb.org/apt/ubuntu bionic/mongodb-org/4.0 multiverse'
Repository will be added to the file
You can now install one of the packages of the new repository is enabled:
$ sudo apt install mongodb-org
If for any reason you want to remove a previously enabled repository, use the option
$ sudo add-apt-repository --remove 'deb [arch=amd64] https://repo.mongodb.org/apt/ubuntu bionic/mongodb-org/4.0 multiverse'
Adding PPA Repository
Personal Package Archives (PPA) is a service that allows users to upload Ubuntu source packages are prepared and published by Launchpad as appropriate repository.
When adding a PPA repository, the command
add-apt-repositorycreates a new file under the directory
For example, to add the PPA Jonathon F providing FFmpeg version 4.x you will run:
$ sudo add-apt-repository ppa:jonathonf/ffmpeg-4
When prompted press the Enter key and a repository will be activated.
Output Press [ENTER] to continue or Ctrl-c to cancel adding it.
PPA repository public key will be automatically downloaded and registered.
After the PPA is added to your system, you can install the package repository:
$ sudo apt install ffmpeg
aptwill install a package and all its dependencies.
Adding Repository Manually
If you want to have more control over how your sources is set, you can edit the file
/etc/apt/sources.listmanually and add lines to the file repository apt.
For the demonstration, I’ll turn on CouchDB repository and install the software. CouchDB is a NoSQL database tolerant and free open source managed by the Apache Software Foundation.
To add a repository, open the file
sources.listwith your text editor:
$ sudo nano /etc/apt/sources.list
Add this line to the end of the file repository:
$ 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 file to the repository lines
$ 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 code name. For example, if you have a version of Ubuntu will print command 18:04
Another option is to create a new repository files under a directory
When configuring the repository manually, you also need to manually import the public key repository to your system. To do that use
$ curl -L https://couchdb.apache.org/repo/bintray-pubkey.asc | sudo apt-key add -
The above command should display OK, which means that the GPG key has been successfully imported and parcel of this would be considered a trusted repository.
Before installing packages from the newly added repository, you must update the package index:
$ sudo apt update
Once the index is updated package, you can install the package from the new repository is added:
$ sudo apt install couchdb
I have shown you how to add repositories apt in Ubuntu. The same instructions apply for Debian-based Linux distributions, including Ubuntu, Linux Mint and Elementary OS.