- How to Add a Package Repository to Debian, Ubuntu and Mint
- Understanding APT Repository on Debian and Ubuntu
- Automatic APT Repositories
- Non-Automatic or Trivial APT Repositories
- Manually Adding APT Repository on Debian and Ubuntu
- Adding APT Repository Using apt-add-repository Command
- Adding Personal Package Archives (PPAs)
- Removing a PPA Repository
- Adding a Package Repository Using GUI Utilities
- How To Add Apt Repository In Ubuntu and Debian?
- “add-apt-repository command not found” Error
- Install add-apt-repository Command
- Add Apt Repository with add-apt-repository Command
- Add PPA Repositories
- Add Repository Manually via sources.list Configuration File
- Remove Specified Repository with add-apt-repository Command
How to Add a Package Repository to Debian, Ubuntu and Mint
A package repository (repo in short) is a location where software packages are stored and can be retrieved from. It is organized in a special directory tree, and usually contains an index file and the metadata needed by Linux package managers to access the packages in the repo and their dependencies.
Package managers such as APT (Advanced Packaging Tool – the default on Debian-like systems) enable you to automatically install and upgrade packages from a configured repo.
They also feature dependency resolution capabilities and software update checking. Besides, all package managers if not most, enable removing a package that is no longer needed.
Attention: Before we proceed, remember to only add software repositories from sources that you trust!
This guide shows how to add a package repository in Debian and Ubuntu Linux, as well as their derivatives such as Linux Mint.
Understanding APT Repository on Debian and Ubuntu
The APT package manager fetches packages from various repositories. A repository can be binary or source, and automatic or trivial. It can also be online or offline (for example on a CD-ROM) but the former is the more common use. Additionally, a repo can be official (maintained by Debian or Ubuntu/Canonical) or unofficial (third party).
A repository is defined in the /etc/apt/sources.list configuration file or in a file stored under the /etc/apt/sources.list.d directory. Every repo file must end with the .list extension.
In a repository file, each line has the following syntax.
deb URI distribution component1 component2 … componentN OR deb-src URI distribution component1 component2 … componentN
The first parameter specifies the archive type (deb – for binary or deb-src – for source files), next is the URI – the root of the repository, then the distribution, and one or more components.
Automatic APT Repositories
To define an automatic repository, you must specify one distribution and one or more components and the distribution must not end with a slash.
The following are examples of automatic repo definitions:
deb http://repository.spotify.com stable non-free deb https://ftp.postgresql.org/pub/pgadmin/pgadmin4/apt/focal pgadmin4 main deb https://download.mono-project.com/repo/ubuntu stable-focal main
Non-Automatic or Trivial APT Repositories
For non-automatic repos, the distribution specifies the relative path to the index files and it must end with a slash. Besides, no components may be specified.
deb http://cloud.r-project.org/bin/linux/debian bullseye-cran40/ deb file:///home/tecmint/rep-exact binary/
Importantly, APT relies on the local package index, a database of available packages from the repositories defined in the /etc/apt/sources.list file and files under the /etc/apt/sources.list.d directory. You can find the package index files under the /var/lib/apt/lists/ directory.
After making changes to the repo configurations, you must always update the local package index before installing or updating packages.
$ sudo apt update OR $ sudo apt-get update
Note: Usually, software owners or maintainers will provide a means either manually or automatically to add the required repository from which you can install their package(s) on your Linux system.
Let’s look at how to add the apt repository, as explained below.
Manually Adding APT Repository on Debian and Ubuntu
To add a repository manually, simply create the repo file under the /etc/apt/sources.list.d directory. We don’t recommend adding all repositories in the /etc/apt/sources.list file.
This example shows how to add the R software environment packages repository.
$ sudo vim /etc/apt/sources.list.d/r-packages.list
Copy and paste the repo configuration into the file and make sure that the parameters such as URI and distribution and components match what is defined in the repository:
deb https://cloud.r-project.org/bin/linux/ubuntu focal-cran40/
Then add the repository key using the following wget command.
$ wget -qO- https://cloud.r-project.org/bin/linux/ubuntu/marutter_pubkey.asc | sudo tee -a /etc/apt/trusted.gpg.d/cran_ubuntu_key.asc
Alternatively, you can also add the repo using the echo and tee commands as follows:
$ echo "deb https://cloud.r-project.org/bin/linux/ubuntu focal-cran40/" | sudo tee /etc/apt/sources.list.d/r-packages.list $ wget -qO- https://cloud.r-project.org/bin/linux/ubuntu/marutter_pubkey.asc | sudo tee -a /etc/apt/trusted.gpg.d/cran_ubuntu_key.asc
Next, you need to update the local package index with the latest changes made in the repositories and then install a package from the repository, as follows:
$ sudo apt update $ sudo apt install --no-install-recommends r-base
To disable an apt repository, simply comment it out in the repository configuration file as shown in the following screenshot.
Adding APT Repository Using apt-add-repository Command
The add-apt-repository command-line utility is used to add a repository into the /etc/apt/sources.list file or /etc/apt/sources.list.d directory. If a repository already exists, it can remove it using the -r flag.
If the add-apt-repository utility is not available on your system, you can install the software-properties-common package which provides it:
$ sudo apt update $ sudo apt install software-properties-common
Let’s look at the following example. The first command adds the repo and the second one retrieves the repo key using the wget utility and saves it to the specified file using the tee utility:
$ sudo add-apt-repository "deb https://cloud.r-project.org/bin/linux/ubuntu $(lsb_release -cs)-cran40/" $ wget -qO- https://cloud.r-project.org/bin/linux/ubuntu/marutter_pubkey.asc | sudo tee -a /etc/apt/trusted.gpg.d/cran_ubuntu_key.asc
If you try to add a repo that already exists, the add-apt-repository command will show the message “Repository already exists” as shown in the following screenshot.
The next step is to update the apt package index and install a package from the repository, as shown before:
$ sudo apt update $ sudo apt install --no-install-recommends r-base
Adding Personal Package Archives (PPAs)
PPAs are software repositories for publishing user-contributed software packages via Launchpad. This example shows how to add the Shutter screenshot tool’s official PPA.
$ sudo add-apt-repository ppa:shutter/ppa $ sudo apt-get update $ sudo apt install shutter
Removing a PPA Repository
To remove a repo using the apt-add-repository utility, use its -r or —remove flag as mentioned earlier:
$ sudo add-apt-repository -r "deb https://cloud.r-project.org/bin/linux/ubuntu $(lsb_release -cs)-cran40/"
Adding a Package Repository Using GUI Utilities
Last but not least, you can also add a repo to your system using a GUI application. On Ubuntu, open Software & Updates via the Activities search bar.
Then switch to the Other Software tab as highlighted in the following screenshot. Next, click Add and enter the repo configuration and follow the prompts.
On Linux Mint, open your system menu and search for Software Sources, then open it. When asked to authenticate, enter your password to invoke the application with root privileges.
Next, click on the Additional Repositories tab, then click the Add button.
In the pop window, add the repo and click OK.
Once the repo has been added successfully, a message will display at the bottom of the window. Click OK to proceed.
Then wait for the local package index to update. Once it is OK, you can proceed to install packages from the just added repo.
That’s it for now! In this guide, we have shown different ways to add a package repository in Debian and Ubuntu Linux, and their derivatives such as Linux Mint. For any comments or questions, reach us via the feedback form below.
How To Add Apt Repository In Ubuntu and Debian?
Ubuntu and Debian use the apt repositories in order to download and install packages. Apt repositories provide the *.deb packages with their metadata information. Ubuntu and Debian provide official Apt repositories with a lot of packages. But in some cases 3rd party apt repositories can be used to install different software packages. The add-apt-repository command is used to add new or 3rd party repositories.
“add-apt-repository command not found” Error
The add-apt-repository command is not installed by default. If you try to run this command you will get the “add-apt-repository command not found” error. If you get this error you should install this tool which is described in the following step.
Install add-apt-repository Command
The add-apt-repository command is provided with the package named software-properties-common. So we will install this package like below.
sudo apt install software-properties-common
Add Apt Repository with add-apt-repository Command
The basi syntax of the add-apt-repository is like below.
add-apt-repository OPTION REPOSITORY
- OPTION is used to provide options to the command. This option is optional.
- REPOSITORY is the repository URL we want to add. This option is required.
In the following example we will add a repository about the get.deb.net. As repository change is administrative task it requires root privileges which can be provided with the sudo command. Also the add-apt-get can run as a root user.
sudo add-apt-repository "deb http://archive.getdeb.net/ubuntu wily-getdeb games"
Security is important part of today IT. Ass the add-apt-repository command adds 3rd party repositories to install software into the Linux system the packages should be verified by this repository in order to prevent breaches. Adding apt repository can be made secure with the public and private keys where a key server should be specified for a specific repository. The key server is specified with the –keyserver and –recv options by using the apt-key command. The –keyserver is used to specify the key server and –recv is used to specify start of the public key we want to import.
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 9DA31620334BD75D9DCB49F368818C72E52529D4
Add PPA Repositories
The Apt repositories also expressed as PPA repositories. The PPA repository is a repository that is generally owned personally or by a group of independent developers. The Launchpad provides the PPA repositories. The add-apt-repository command can be also used to add PPA repositories.
sudo add-ppa-repository ppa:libreoffice/ppa
The PPA repositories have the following naming syntax.
- ppa is used to express this is a PPA repository.
- USER is the PPA username which is created by LaunchPad.
- NAME is the PPA name where a single user may provide multiple PPA repositories.
Add Repository Manually via sources.list Configuration File
The repository information is stored in the /etc/apt/sources.list configuration file. Every line is a repository in this file. The add-apt-repository command actually adds provided repository into this file. We can also manually add repositories in this configuration file. Like add-apt-repository command we will open sources.list file with the root privileges by using sudo command.
sudo nano /etc/apt/sources.list
We will just add the following line to the end of the file. The # sign at the start of the line makes this line comment and it will not interpreted as repository. Just put following line.
deb http://archive.getdeb.net/ubuntu wily-getdeb games
A repository can be disabled by using # sign by making it comment. As an example the following repository configyration is disable by commenting it.
Remove Specified Repository with add-apt-repository Command
Even the add-apt-repository command is created to add new repositories it can be also used to remove the existing repository. The -r or –remove option can be used to remove the specified repository. The repository is specified with its URL or PPA. Also like adding a repository removing a repository requires the root privileges which can be provided with the sudo command.
sudo add-apt-repository -r "deb http://archive.getdeb.net/ubuntu wily-getdeb games"