How to disable yum repository

Disable specific yum repository to prevent particular packages from installation or update.

Operating system.

$ cat /etc/centos-release
CentOS Linux release 7.6.1810 (Core)

Display configured repositories.

$ yum repolist all     
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: centos.hitme.net.pl
 * extras: mirror-pl.kielcetechnologypark.net
 * updates: mirror-pl.kielcetechnologypark.net
repo id                                                                           repo name                                                                          status
base/7/x86_64                                                                     CentOS-7 - Base                                                                    enabled: 10097
base-debuginfo/x86_64                                                             CentOS-7 - Debuginfo                                                               disabled
base-source/7                                                                     CentOS-7 - Base Sources                                                            disabled
c7-media                                                                          CentOS-7 - Media                                                                   disabled
centosplus/7/x86_64                                                               CentOS-7 - Plus                                                                    disabled
centosplus-source/7                                                               CentOS-7 - Plus Sources                                                            disabled
cr/7/x86_64                                                                       CentOS-7 - cr                                                                      disabled
extras/7/x86_64                                                                   CentOS-7 - Extras                                                                  enabled:   304
extras-source/7                                                                   CentOS-7 - Extras Sources                                                          disabled
fasttrack/7/x86_64                                                                CentOS-7 - fasttrack                                                               disabled
google-cloud-compute                                                              Google Cloud Compute                                                               enabled:    11
google-cloud-sdk                                                                  Google Cloud SDK                                                                   enabled:   906
updates/7/x86_64                                                                  CentOS-7 - Updates                                                                 enabled:   311
updates-source/7                                                                  CentOS-7 - Updates Sources                                                         disabled
repolist: 11629

Inspect google-cloud-compute and google-cloud-sdk repository configuration.

$ cat /etc/yum.repos.d/google-cloud.repo 
[google-cloud-compute]
name=Google Cloud Compute
baseurl=https://packages.cloud.google.com/yum/repos/google-cloud-compute-el7-x86_64
enabled=1
gpgcheck=1
repo_gpgcheck=1
gpgkey=https://packages.cloud.google.com/yum/doc/yum-key.gpg
         https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg
ip_resolve = ipv4
keepcache = 0
[google-cloud-sdk]
name=Google Cloud SDK
baseurl=https://packages.cloud.google.com/yum/repos/cloud-sdk-el7-x86_64
enabled=1
gpgcheck=1
repo_gpgcheck=1
gpgkey=https://packages.cloud.google.com/yum/doc/yum-key.gpg
         https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg
ip_resolve = ipv4
keepcache = 0

Disable google-* repositories.

$ sudo yum-config-manager --disable google-\*

Display configured repositories.

$ yum repolist all
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: centos.hitme.net.pl
 * extras: mirror-pl.kielcetechnologypark.net
 * updates: mirror-pl.kielcetechnologypark.net
repo id                                                                           repo name                                                                          status
base/7/x86_64                                                                     CentOS-7 - Base                                                                    enabled: 10097
base-debuginfo/x86_64                                                             CentOS-7 - Debuginfo                                                               disabled
base-source/7                                                                     CentOS-7 - Base Sources                                                            disabled
c7-media                                                                          CentOS-7 - Media                                                                   disabled
centosplus/7/x86_64                                                               CentOS-7 - Plus                                                                    disabled
centosplus-source/7                                                               CentOS-7 - Plus Sources                                                            disabled
cr/7/x86_64                                                                       CentOS-7 - cr                                                                      disabled
extras/7/x86_64                                                                   CentOS-7 - Extras                                                                  enabled:   304
extras-source/7                                                                   CentOS-7 - Extras Sources                                                          disabled
fasttrack/7/x86_64                                                                CentOS-7 - fasttrack                                                               disabled
google-cloud-compute                                                              Google Cloud Compute                                                               disabled
google-cloud-sdk                                                                  Google Cloud SDK                                                                   disabled
updates/7/x86_64                                                                  CentOS-7 - Updates                                                                 enabled:   311
updates-source/7                                                                  CentOS-7 - Updates Sources                                                         disabled
repolist: 10712

Inspect google-cloud-compute and google-cloud-sdk repository configuration.

$ cat /etc/yum.repos.d/google-cloud.repo 
[google-cloud-compute]
name=Google Cloud Compute
baseurl=https://packages.cloud.google.com/yum/repos/google-cloud-compute-el7-x86_64
enabled=0
gpgcheck=1
repo_gpgcheck=1
gpgkey=https://packages.cloud.google.com/yum/doc/yum-key.gpg
         https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg
ip_resolve = ipv4
keepcache = 0
[google-cloud-sdk]
name=Google Cloud SDK
baseurl=https://packages.cloud.google.com/yum/repos/cloud-sdk-el7-x86_64
enabled=0
gpgcheck=1
repo_gpgcheck=1
gpgkey=https://packages.cloud.google.com/yum/doc/yum-key.gpg
         https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg
ip_resolve = ipv4
keepcache = 0

Enable google-cloud-sdk and google-cloud-compute repositories.

$ sudo yum-config-manager --enable google-cloud-sdk --enable google-cloud-compute

Confirm that these repositories are enabled.

$ yum repolist enabled
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: centos.hitme.net.pl
 * extras: mirror-pl.kielcetechnologypark.net
 * updates: mirror-pl.kielcetechnologypark.net
repo id                                                                               repo name                                                                              status
base/7/x86_64                                                                         CentOS-7 - Base                                                                        10097
extras/7/x86_64                                                                       CentOS-7 - Extras                                                                        304
google-cloud-compute                                                                  Google Cloud Compute                                                                      11
google-cloud-sdk                                                                      Google Cloud SDK                                                                         906
updates/7/x86_64                                                                      CentOS-7 - Updates                                                                       311
repolist: 11629