How To Add/Remove A Software Repository In Linux?


Gaming Laptop Series

Software Repository

A software repository(also called ‘repo’) is the database of software packages stored on a remote server. The server also contains metadata of packages. Generally, these packages are retrieved by using a package manager in the local machine. When you install a distribution of Linux it comes with a pre-configured default repository to download the applications, but sometimes it is needed to download the software from a different source that is not listed in default repositories. In this case, first, you will have to add the repository into the system and then you can perform the installation process of software.

Ahead in this article, we will discuss adding and removing software repositories in different distributions of Linux.


Adding a repository in debian based systems

In debian based systems such as Ubuntu, Linux Mint, elementary OS, etc repositories are managed via sources.list file. And can be edited by using a single file that is /etc/apt/sources.list. Now follow the below steps to edit it –

1. Open this file by using a text editor

sudo nano /etc/apt/sources.list

2. To enable a repository, remove the hash sign which is given at the beginning of the repository URL

#deb cdrom:[Linux Mint 19.2 _Tina_ - Release amd64 20190729]/ bionic contrib main non-free

Change it to –

deb cdrom:[Linux Mint 19.2 _Tina_ - Release amd64 20190729]/ bionic contrib main non-free

3. Save the file
Now save the file in the nano text editor by pressing ctrl+o followed by return key or :wq(in command mode) followed by the return key if you are using a vi text editor.

You can also add a repository from the terminal, follow the below steps –

1. Open your terminal by pressing  ctrl+alt+t
2. Add a repository

sudo add-apt-repository repository_url

For example-

sudo add-apt-repository ppa:danielrichter2007/grub-customizer

and press enter

3. Now update the apt package index with

sudo apt update

The repository is now added to the system. You can install the software from the source.


Remove repository in Debian based systems

To remove a software repository from the debian based system put # (hash) at the beginning of repository URL –
1. Open /etc/apt/source.list with a text editor

sudo nano /etc/apt/source.list

To disable a repository add the # (hash) at the starting of the line

deb cdrom:[Linux Mint 19.2 _Tina_ - Release amd64 20190729]/ bionic contrib main non-free

change to

#deb cdrom:[Linux Mint 19.2 _Tina_ - Release amd64 20190729]/ bionic contrib main non-free

2. Now save the file and exit from the text editor.

To remove a repository from the terminal, use the following command –

sudo add-apt-repository -r repository_url

for example-

sudo add-apt-repository -r ppa:danielrichter2007/grub-customizer

Adding a repository in CentOS and Fedora

In CentOS and Fedora repositories are managed by .repo files. These are the text files that reside in /etc/yum.repos.d directory. To add a repository from the terminal in a distribution which uses yum package manager, follow the below steps –

1. Open the terminal by pressing ctrl+alt+t
2. Execute the following command into your terminal

yum-config-manager --add-repo repository_url

For example –

yum-config-manager --add-repo http://www.example.com/example.repo

To enable the repository use –

yum-config-manager --enable repository_url

To add repository in fedora use –

dnf config-manger --add-repo repository_url

For example –

dnf config-manager --add-repo /etc/yum.repos.d/fedora_extras.repo

To enable the repository use –

dnf config-manager --set-enabled fedora-extras

Remove the software repository from CentOS and Fedora

You can remove a software repository from the CentOS and Fedora in the following ways –

1. Open the file /etc/yum.repos.d/repository_name.repo in CentOS. Or /etc/yum.repos.d/fedora_extras.repo in fedora by using a text editor and change enabled=1 to enabled=0 and then save it and exit from the editor.

2. Or you can delete the .repo file from the /etc/yum.repos.d directory. To delete .repo file use the following commands –

In CentOS use –

sudo rm /etc/yum.repos.d/repository_name.repo

In Fedora use –

sudo rm /etc/yum.repos.d/fedora_extras.repo

3. Or use the following commands to disable a repository from the terminal-

To disable a repository in CentOS use –

yum-config-manager --disable repository_name

To disable the repository in Fedora use –

dnf config-manager --set-disabled fedora-extras

I hope this will give you a basic understanding of using a software repository in Linux. If you still have any queries regarding this you can write us in comments.

1 thought on “How To Add/Remove A Software Repository In Linux?”

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.