How to enable or disable repositories in CentOS

0
62

I am sure most of you use many YUM repositories to install softwares on any RPM based distributions like RHEL, CentOS, Fedora etc. Sometimes, you might want to install a software from a group of specific repositories, or you may want to disable all repositories, and install a package from a single repository. If you ever wonder how to do that, here you go.

This short tutorial describes how to enable or disable a single or group of YUM repositories while installing softwares in CentOS. This guide was tested on CentOS 7 server, however the same method should work on Fedora, RHEL, Scientific Linux, and other RPM based Linux distributions.

Let us get started.

As you already know, we can list the number of available repositories in CentOS using the following command as root user:

yum repolist

Sample output:

Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.vinahost.vn
 * epel: mirror.rise.ph
 * extras: mirrors.viethosting.vn
 * remi-safe: rpms.remirepo.net
 * updates: mirrors.vinahost.vn
repo id repo name status
base/7/x86_64 CentOS-7 - Base 9,007
epel/x86_64 Extra Packages for Enterprise Linux 7 - x86_64 10,075
extras/7/x86_64 CentOS-7 - Extras 305
remi-safe Safe Remi's RPM repository for Enterprise Linux 7 - x86_64 820
updates/7/x86_64 CentOS-7 - Updates 1,676
repolist: 21,883

Deepin-Terminal_001

As you see in the above output, I have added two more additional repositories namely EPEL, and REMI. These are the important repositories that provides packages which are not found in the CentOS official repositories.

One thing is whenever you run “yum update” command, those additional repositories will be updated. So, the packages from that repositories will also be updated to the latest available versions. Sometimes, you don’t want to install the latest packages, and want to stick with the old versions instead. In such cases, you can exclude a repository, so that the packages from that repositories will not be upgraded too. This will be helpful when a software needs a particular version package to work well.

We can enable or disable repositories in two ways.

  1. Temporarily enable or disable repositories while installing packages using ‘yum’ command
  2. Permanently Enable/Disable repositories using repository configuration file

1. Enable or disable repositories temporarily

This is my preferred method. In this method, We can temporarily exclude a repository to prevent a package from being updated.

Let us see an example.

yum --disablerepo=remi-safe update

Or,

yum update --disablerepo=remi-safe

The above command disable the REMI repository temporarily and update out CentOS system.

To disable multiple repository, just include the repository separated by comma as shown like below.

yum --disablerepo=remi-safe,updates update

The above command will disable REMI and updates (CentOS official repository) temporarily.

You can use method to install a package too.

yum --disablerepo=remi-safe,updates install httpd

Sample output:

Deepin-Terminal_002

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

Take a look at the following command.

yum --disablerepo=* --enablerepo=epel update

Sample output:

Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * epel: mirror.pregi.net
No packages marked for update

The above command will disable all other repositories except the ‘epel’ repository.

2. Enable or disable a repository permanently

This method will 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 command.

ls /etc/yum.repos.d/

Sample output:

CentOS-Base.repo CentOS-Media.repo epel-testing.repo
CentOS-CR.repo CentOS-Sources.repo remi-php70.repo
CentOS-Debuginfo.repo CentOS-Vault.repo remi.repo
CentOS-fasttrack.repo epel.repo remi-safe.repo

Let us disable a repository, for example EPEL.

To do so, edit EPEL repository file:

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

Deepin-Terminal_004

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

yum repolist

Similarly, change the value of ‘enabled’ line to 1 to enable the repository.

You know now how to enable or disable a particular or group of repositories. As you can see in this tutorial, this is very easy to do. That’s all for now. Hope this guide help you.

Print Friendly

Comments

comments