How to enable or disable repositories in CentOS

To enable or disable repositories in CentOS

This tutorial describes how to enable or disable a single or group of YUM repositories while installing software on CentOS. Sometimes, having them already enabled in your system will help you save a lot of time. This tutorial tests the same process on CentOS 7 server. 

 

Enabling or disabling repositories 

First, you need to check the repo list which you can do by making use of the following command. 

[root@linuxhelp ~]# yum repolist
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.vinahost.vn
.
updates/7/x86_64 CentOS-7 - Updates 1,676
repolist: 21,883

We can enable or disable repositories in two ways.
Temporarily enable or disable repositories while installing packages using ‘ yum’  command
Permanently Enable/Disable repositories using repository configuration file


To disable multiple repository, just include the repository separated by comma

[root@linuxhelp ~]# yum --disablerepo=remi-safe,updates update
[root@linuxhelp ~]# yum --disablerepo=remi-safe,updates update
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
.
Complete!


You can use method to install a package too.

[root@linuxhelp ~]# yum --disablerepo=remi-safe,updates install httpd
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
.
Installed:
  httpd.x86_64 0:2.4.6-67.el7.centos                                                                                

Complete!

 

Similarly, you can both enable and disable a particular repositories at a time with ‘ yum’ command.

[root@linuxhelp ~]# yum --disablerepo=* --enablerepo=epel 
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * epel: mirror.pregi.net
No packages marked for update
You can also permanently enable or disable a repository. Usually, the repository configuration files will be saved in the /etc/yum.repos.d/ directory.


Let us see the available repositories using the following command.

[root@linuxhelp ~]# ls /etc/yum.repos.d/
CentOS-Base.repo       CentOS-fasttrack.repo  CentOS-Vault.repo  remi-php54.repo  remi-php72.repo
CentOS-CR.repo         CentOS-Media.repo      epel.repo          remi-php70.repo  remi.repo
CentOS-Debuginfo.repo  CentOS-Sources.repo    epel-testing.repo  remi-php71.repo  remi-safe.repo


To do so, edit EPEL repository file:

[root@linuxhelp ~]# vi /etc/yum.repos.d/epel.repo
Change the value enabled=1 to 0 (zero).
epel]
name=Extra Packages for Enterprise Linux 7 - $basearch
#baseurl=http://download.fedoraproject.org/pub/epel/7/$basearch
mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-7& arch=$basearch
failovermethod=priority
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7


Save and close the file. Update the repository lists to take effect the changes.

[root@linuxhelp ~]# yum repolist 
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
.


With this, the tutorial comes to an end.  

FAQ
Q
How to disable a repository on CentOS?
A
For disable the repository on CentOS, use the following command as given below "yum-config-manager --disable repository..."
Q
How to check the available repository list on CentOS?
A
For check, the available repository list on CentOS, use the following command as given below "yum repolist"
Q
How to remove the repository on Ubuntu?
A
For remove the repository on Ubuntu, use the following link as given below, https://www.linuxhelp.com/how-to-remove-repositories-on-ubuntu-16-04/
Q
How to Configure a network repository?
A
To configure the network repository, use the following link as given below "https://www.linuxhelp.com/installupdate-packages-setup-network-repository/"
Q
How to enable the Remi repository on centos?
A
To enable the Remi repository on CentOS, use the following steps as below,
"yum install epel-release -y
cd /usr/local/src/
wget https://rpms.remirepo.net/enterprise/remi-release-7.rpm
rpm -Uvh Remi-release-7.rpm"