Introduction
Before we begin talking about how to add Apt Repository on Ubuntu, let's briefly understand – What is an Apt Repository ?
An Apt Repository is a central location that stores software packages for APT. It provides a secure and organized way to access, download, and install software packages, updates, and patches. Apt Repositories ensure easy software management, support for multiple versions, and efficient distribution.
When installing packages through the Ubuntu Software Center or command line tools like apt
or apt-get
, the packages are downloaded from one or more apt software repositories. An APT repository is a local directory or a network server that stores deb packages and metadata files that the APT tools can read.
Even though the default Ubuntu repositories contain thousands of applications, there are times when you will need to install software from a third-party repository.
In this tutorial, you will add apt repository on Ubuntu. We will also address a few FAQs on how to add apt repository on Ubuntu.
Advantages of Apt Repository
- Centralized Software Management: Apt Repositories provide a centralized location for storing and managing software packages.
- Easy Access to Packages: Users can easily access, download, and install software packages from the repository.
- Efficient Updates: Apt Repositories ensure efficient distribution of software updates and patches.
- Multiple Version Support: Apt Repositories allow users to access and install different versions of software packages.
- Enhanced System Security: Apt Repositories provide a reliable source for secure software updates, improving system security and stability.
Apt Sources
The apt software repositories on Ubuntu and other Debian-based distributions are defined in the /etc/apt/sources.list
file or in different files under the /etc/apt/sources.list.d/
directory.
The repository files in the /etc/apt/sources.list.d/
directory must have a name that ends with .list
.
The /etc/apt/sources.list
file's general syntax requires the following format:
deb http://repo.tld/ubuntu distro component...
- The archive type is specified by the first entry in the line. Either deb or deb-src may be used as the archive type. Deb suggests that the repository includes
.deb
packages while deb-src implies source packages. - The repository URL is the second entry.
- The distribution code name, such as beaver, xenial, and so on, is specified in the third entry.
- The repository's components or categories are the last entries. Four components make up the default Ubuntu repositories: main, restricted, universe, and multiverse. Typically, third-party repositories only have one category.
The files in the /etc/apt/sources.list.d/
directory have the same format as the standard sources.list
file.
The majority of repositories include a public key for authenticating downloaded packages that must be downloaded and imported.
You must be logged in as root or a user with sudo privileges in order to add or remove a repository.
Generally, the software documentation has instructions on how to enable a certain repository.
Installing add-apt-repository
(add-apt-repository command not found)
add-apt-repository
is a Python script for adding an APT repository to /etc/apt/sources.list
or a separate file in the /etc/apt/sources.list.d
directory. An existing repository can also be removed with this command.
An error message stating “add-apt-repository command not found” will appear if the add-apt-repository
is not available on your system.
The software-properties-common
package contains the add-apt-repository
utility. Use the following commands to install it:
sudo apt update
sudo apt install software-properties-common
Adding Repositories with add-apt-repository
The add-apt-repository
command's general syntax is as follows:
add-apt-repository [options] repository
Where repository
might be either a conventional repository entry that can be added to the sources.list
file such as a deb http://repo.tld/ubuntu distro component
or a PPA repository in the ppa:<user>/<ppa-name>
format.
In your terminal, type man add-apt-repository
to see all the options for the add-apt-repository
command.
With Ubuntu 18.04 and newer, if the repository public key is imported, the add-apt-repository
will by default also update the package index.
The package index is a database that lists all the packages that are currently accessible from the repositories that are enabled in your system.
Let us assume you wish to install MongoDB from their official repository.
To begin, import the repository public key:
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 9DA31620334BD75D9DCB49F368818C72E52529D4
Use the command below to add the MongoDB repository:
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 sources.list
.
Now that the repository has been enabled, you can install any of the packages:
sudo apt install mongodb-org
Use the --remove
option if you need to remove a repository that was previously enabled for any reason:
sudo add-apt-repository --remove 'deb [arch=amd64] https://repo.mongodb.org/apt/ubuntu bionic/mongodb-org/4.0 multiverse'
Adding PPA Repositories
Personal Package Archives (PPA) is a service that allows users to upload Ubuntu source packages that have been developed and published as an apt repository using Launchpad.
When you add a PPA repository, the command add-apt-repository
creates a new file in the /etc/apt/sources.list.d/
directory.
For instance, you would run the following command to add Jonathon F's PPA, which offers FFmpeg version 4.x:
sudo add-apt-repository ppa:jonathonf/ffmpeg-4
When prompted, hit Enter
to enable the repository.
Output
Press [ENTER] to continue or Ctrl-c to cancel adding it.
The public key for the PPA repository will be downloaded and registered automatically.
Install the repository packages after adding the PPA to your system:
sudo apt install ffmpeg
The package and all of its dependencies will be installed using the apt
command.
Manually Adding Repositories
You can manually change the /etc/apt/sources.list
file and insert the apt repository line to the file if you would like more control over how your sources are organized.
We will install the program and enable the CouchDB repository for demonstration purposes. CouchDB is a free and open-source fault-tolerant NoSQL database managed by the Apache Software Foundation.
Open the sources.list
file with your text editor to add the repository:
sudo nano /etc/apt/sources.list
The repository line should be added at the end of the file:
deb https://apache.bintray.com/couchdb-deb bionic main
Use the following command to append the repository line to the sources.list
file instead of editing it with a text editor:
echo "deb https://apache.bintray.com/couchdb-deb $(lsb_release -cs) main" | sudo tee -a /etc/apt/sources.list
The Ubuntu codename will be printed using $(lsb_release -cs)
. For instance, the script will print bionic
if you are on Ubuntu 18.04.
Another method is to add a new repository file under the /etc/apt/sources.list.d/
directory.
You must manually import the public repository key into your system when manually configuring a repository. Use either wget
or curl
to do that:
curl -L https://couchdb.apache.org/repo/bintray-pubkey.asc | sudo apt-key add -
The output of the aforementioned command should be OK
, indicating that the GPG key has been successfully imported and that packages from this repository can be trusted.
You must update the package index before installing the packages from the newly added repository:
sudo apt update
You can install packages from the newly acquired repository once the package index has been updated:
sudo apt install couchdb
FAQs to Add Apt Repository On Ubuntu
Where are the Apt Repository files located?
Apt repository files are typically stored in the /etc/apt/sources.list or in the /etc/apt/sources.list.d/ directory.
How can I check if an Apt Repository is already added?
Run the "apt policy" command followed by the package name to check if the repository is already added to your system.
Can I add a repository that is not specifically designed for Ubuntu?
It is generally recommended to only add repositories designed for Ubuntu to ensure compatibility and avoid potential issues.
What should I do if the repository I added is causing conflicts or issues?
Remove the repository by using the "sudo add-apt-repository --remove" command followed by the repository's URL or package name.
How often should I update the Apt Repository on my Ubuntu system?
It is advisable to regularly update the repository by running the "sudo apt update" command to ensure you have the latest software packages.
Can I add multiple repositories to my Ubuntu system?
Yes, you can add multiple repositories by using the "add-apt-repository" command for each repository you want to add.
Can I add third-party repositories to my Ubuntu system?
Yes, you can add third-party repositories, but make sure they are trustworthy and provide reliable packages to avoid potential security risks.
Conclusion
You now know how to add apt repositories to Ubuntu. The same methods apply to any Debian-based distribution, including Kubuntu, Linux Mint, and Elementary OS.
If you have any suggestions or queries, kindly leave them in the comments section.