On Linux, when you search for a package from the command line, your system's package manager looks for the package in various repositories. By default, every Linux distribution has some official repositories that contain stable packages that are supported by the distribution team.

However, if you try to get a package that is not in the official software repositories, the package manager will display an error message. In such situations, you can manually add the third-party repository to your system and then download the package.

Let's see how to add new repositories to your system's source list.

On Ubuntu and Debian based distributions

Debian-based distributions, including Ubuntu, use the Advanced Package Tool (APT) to install and update packages. Information on the software repository can be found in the /etc/apt/sources.list File in your Debian-based Linux installation.

Although you can manually enter repository details into the file, it can quickly become a tedious job. A better way to add YOU to your system is to use the Add-apt-repository Tool.

Install add-apt repository

You cannot find the add-apt-repository utility installed by default on your system. It's part of the Software properties in general Package. Enter the following to install add-apt-repository using the APT package manager:

sudo apt install software-properties-general

Adding repositories with add-apt-repository

After you've installed the package, it's time to add a third-party software repository to your system. The basic syntax for adding repositories is:

sudo add-apt-repository (options) repository

…Where Repository is the format used by the Sources.List File.

The default input format for the file is:

deb https://repositoryurl.com distribution type

For example, to add the Ubuntu universe repository to your system:

sudo add-apt-repository "deb http://archive.ubuntu.com/ubuntu $ (lsb_release -sc) universe"

You can also add a PPA with add-apt-repository using the following command syntax:

sudo add-apt-repository ppa: user / name

…Where user and Surname is the Owner name and PPA name respectively.

To add Ondrej's PHP PPA using add-apt-repository:

sudo add-apt-repository ppa: ondrej / php

Related: What is the Difference Between APT and DPkg in Ubuntu?

Manually adding repositories on Fedora and CentOS

Fedora, CentOS, and other RHEL-based distributions use DNF and Yum package managers. Unlike APT, DNF has a built-in method Configuration manager This allows users to easily add, remove, and deactivate third party repositories.

Use the DNF Package Manager

To add a new repository using DNF:

dnf config-manager –add-repo repository

…Where Repository is the URL to the software repository.

Enter the following to activate a repository:

dnf config-manager –set-enabled repository

Using yum-config-manager

Alternatively, you can also use the yum-config-manager Utility for adding and managing repositories on your system. By default, Yum-config-manager is not installed on RHEL-based distributions, so you will need to install it manually. It's part of the yum-utils Package. Enter the following to install it:

sudo dnf install yum-utils

The format of the yum-config-manager command is similar to DNF. You can add a new repository using yum-config-manager as follows:

yum-config-manager –add-repo repository

Activating a repository is also easy.

Enable yum-config-manager –repository

Arch Linux and the AUR

If you are using Arch Linux, you may already know that users cannot add repositories on Arch. However, that does not mean that you cannot download additional packages onto your system.

Arch Linux has the AUR, the Arch User Repository, which contains thousands of third-party packages that have been developed by users. You can access the AUR using an AUR package manager. Pacman, Arch Linux's default package manager, cannot access the packages stored in the Arch User Repository.

There are several AUR package managers out there, the most popular one being Yay. You can easily install yay on your system by cloning the Git repository.

git clone https://aur.archlinux.org/yay-git.git

Change the permissions of the downloaded folder:

sudo chmod 777 / yay-git

Change the directory and use the makepkg Command to install yay:

cd / yay-git && makepkg -si

Learn More: How To Install And Remove Packages In Arch Linux

Manage your system's repository list

From a Linux installation to everyday use, repositories are responsible for delivering packages to the system. If you are a beginner, the standard repositories will be enough to suit your needs. However, knowing how to add repositories is definitely beneficial for those who want to download third-party packages onto their computer.

On Linux, when upgrading or installing new packages, you may have encountered the corrupt package error many times. Reinstalling or removing such packages will fix the problem on most Linux systems.

10 ways to improve the speed of your WiFi router

Internet connection too slow? These simple router tweaks can make a huge difference in your home Wi-Fi network.

Continue reading

About the author

Deepesh Sharma
(61 published articles)

Deepesh is Junior Editor for Linux at MUO. He has been writing informational content on the Internet for over 3 years. In his spare time he enjoys writing, listening to music and playing the guitar.

More
From Deepesh Sharma

Subscribe to our newsletter

Subscribe to our newsletter for tech tips, reviews, free e-books, and exclusive offers!

One more step …!

Please confirm your email address in the email we just sent you.