Enabling or disabling a repository using Red Hat Subscription Management

Solution Verified - Updated -

Environment

  • Red Hat Enterprise Linux 5,6,7,8
  • Registered via Red Hat Subscription Management (RHSM)

Issue

  • How to enable a repository using Red Hat Subscription Manager
  • Need to access a repository using Red Hat Subscription Manager
  • How to disable repository using Subscription Manager
  • How to subscribe a child channel using Red Hat Subscription-Manager
  • How can I edit the /etc/yum.repos.d/redhat.repo file?
    • Changes made to redhat.repo are reverted whenever a yum or subscription-manager runs

Resolution

As systems are subscribed to products, the associated content repositories (identified in the entitlement certificate) are made available to the system. The content repositories are based on the product and on the content delivery network, defined in the baseurl parameter of the rhsm.conf file.

List all available repositories for the system, including disabled repositories:

[root@server ~]# yum repolist all
repo id                      repo name                                   status
rhel-6-server                Red Hat Enterprise Linux 6Server            enabled
rhel-6-server-optional-rpms  Red Hat Enterprise Linux 6Server - Optional disabled
rhel-6-server-extras  Red Hat Enterprise Linux 6Server - Extras          disabled

Using Subscription-Manager

subscription-manager provides its own utility to enable & disable repositories ONLY within the redhat.repo file:

To see a list of available repositories:

[root@server ~]# subscription-manager repos --list

To enable a specific Red Hat repository:

[root@server ~]# subscription-manager repos --enable=rhel-6-server-optional-rpms

To disable a specific Red Hat repository:

[root@server ~]# subscription-manager repos --disable=rhel-6-server-optional-rpms

Using Yum-Utils provided yum-config-manager:

The repositories can be enabled or disabled using the yum-config-manager command, which is provided by the yum-utils package:

Note: yum-config-manager is only available for RHEL 6 and later

[root@server ~]# yum install -y yum-utils
[root@server ~]# yum-config-manager --enable <repo-id>
[root@server ~]# yum-config-manager --disable <repo-id>

Enable a repository for a single yum transaction

A repository may be temporarily enabled by using the --enablerepo= option. For example:

# yum install rubygems --enablerepo=rhel-6-server-optional-rpms

Note: if another update is released in the disabled repo, your system will not apply that update unless you enable the repository again. You may also encounter dependency issues if a package being updated by the base repo, requires the package from the disabled repo to update as well

Disabling the Subscription-Manager Repository

When a system is registered using Subscription-Manager, the rhsmcertd process creates a special yum repository — redhat.repo.

Maintaining a redhat.repo file may not be desirable in some environments. It can create static in content management operations if that repository is not the one actually used for subscriptions, such as for a disconnected system or a system using a local content mirror.

This default redhat.repo repository can be disabled by editing the Subscription-Manager configuration and setting the manage_repos value to zero (0).

[root@server ~]# subscription-manager config --rhsm.manage_repos=0

More information: Working with yum Repos


Commonly used repositories

The repositories you want to enable are going to be dependent on the packages you need to install and the product you are using. For RHEL 7 and below, the names generally follow the format of rhel-<Major Release>-<Product>-rpms. For example rhel-7-server-rpms vs rhel-6-workstation-rpms.

To identify what repository contains a package, you can find all of our packages on the portal using the Package Browser. Some packages or errata are only for specific products and may not apply to your product. You can search the Packages tab of the product page to only see packages for your product.

Base Repos Optional/Development Repos
RHEL 6 rhel-6-server-rpms rhel-6-server-optional-rpms
RHEL 7 rhel-7-server-rpms rhel-7-server-optional-rpms
RHEL 8 rhel-8-for-x86_64-baseos-rpms
rhel-8-for-x86_64-appstream-rpms
codeready-builder-for-rhel-8-x86_64-rpms

These will provide the most common packages used on a basic system. If you are using a different base product, such as Workstation, replace "server" with "workstation". If you are using a different architecture for RHEL 8, this will be reflected in the repository name.

If you are using a more advanced Red Hat product, refer to the product documentation to find which product specific repositories should be enabled.

Root Cause

subscription-manager maintains the redhat.repo file. Whenever it's run by itself or as a yum plugin, it will set the redhat.repo back to it's last saved state, undoing any manual changes made.

 # head /etc/yum.repos.d/redhat.repo
 #
 # Certificate-Based Repositories
 # Managed by (rhsm) subscription-manager
 #
 # *** This file is auto-generated.  Changes made here will be over-written. ***
 # *** Use "subscription-manager repo-override --help" if you wish to make changes. ***
 #
 # If this file is empty and this system is subscribed consider
 # a "yum repolist" to refresh available repos
 #

You can disable this by disabling "manage_repos" in /etc/rhsm/rhsm.conf OR you can modify the redhat.repo file with the repo-override command.

This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.

15 Comments

Just a quick note:

suscription-manager only handles /etc/yum.repos.d/redhat.repo

To fully disable all yum repos you need both of these

subscription-manager repos --disable=*

yum-config-manager --disablerepo=*

Also note, when making to make sure you don't having missing dependencies and to ensure you don't have other conflicts run the following:

repoclosure

Why would you want to disable all repos?

There are some use cases for this.

Sometimes it is such that there are numerous repos enabled, and you want to make sure that only specific ones are switched on.

Suppose you need three specific repos, ONLY but there are nine enabled.

It's easier to disable all of them, then enable three, versus disabling all except those particular three.

Thank you. Because we use openldap for access to satellite server we chose option 2. I enable the optional channel and resolved the issue. This ticket may be closed. Thanks, Lonnie Furnish

sometimes, it will get failed result when enable repos, what's the reason?

Perhaps there has been a mistake in the repo ID?

when i want to config /etc/yum.repos.d/redhat.repo, but everty time this file will be rewirte,why?

The file is managed by the subscription-manager application, the yum-config-manager tool, as well as various GUI tools. These tools should respect manual settings in the file, but if you use them to change settings, they will overwrite the file.

Hi, I can not update red hat 6.5 on my servers. I get the message below:

yum repolist all

Loaded plugins: product-id, refresh-packagekit, security repo id repo name status rhel-source Red Hat Enterprise Linux 6Server - x86_64 - Source disabled rhel-source-beta Red Hat Enterprise Linux 6Server Beta - x86_64 - Source disabled repolist: 0

subscription-manager repos --list

Ce système ne possède pas de référentiel disponible à travers des abonnements.

subscription-manager repos --disable=rhel-6-server-optional-rpms

Erreur : rhel-6-server-optional-rpms n'est pas un ID de référentiel valide. Utilisez l'option --list pour afficher les référentiels valides. I get suscription recently. Thank you for your assistance. Best regards,

First you need to attach subscription by running # subscription-manager attach --auto then # subscription-manager repos --list to list the repositories.

How do I enable all repos that my subscription allows ?

for example, something like subscription-manager repos --enable=*

If this is a suitable/good/OK thing to do? If not, why not? Just to ask.

DEAR SIR PL GUIDE HOW TO INSTALL XFIG AND KATE IN RHEL 7.7 IN TERMINAL MODE PLEASE GUIDE STEP BY STEP WITH FULL COMMAND THANKS

Kindly request this article be updated to include subscription-manager examples for RHEL 7 and 8.

Some repos I assigned were:

### NOTE: I AM RESEARCHING IF ALL OF THESE ARE APPROPRIATE OR NOT FOR RHEL7
subscription-manager repos --enable rhel-7-server-extras-rpms
subscription-manager repos --enable rhel-7-server-thirdparty-oracle-java-rpms
subscription-manager repos --enable rhel-7-server-rh-common-rpms
subscription-manager repos --enable rhel-7-server-rpms
subscription-manager repos --enable rhel-7-server-supplementary-rpms
subscription-manager repos --enable rhel-7-server-optional-rpms

Regards,
RJ

I can update the Environment to include RHEL 7 and RHEL 8. The commands are the same with only the repository names differing. A RHEL 5,6,7 Server only needs rhel-#-server-rpms at a minimum. The rhel-7-server-optional-rpms repository is often needed for many customers. Otherwise it's really dependent on the systems needs. For RHEL 8 we need 2 repositories. rhel-8-for-x86_64-appstream-rpms and rhel-8-for-x86_64-baseos-rpms. For development some customers also require codeready-builder-for-rhel-8-x86_64-rpms. Anything else is user or Product specific (such as a repository for Red Hat Enterprise Virtualization)

hi John, that would be great because we get this as a recurring question on the Red Hat Discussion forums where I and a few other community leaders attempt to point folks to good answers, and I think given the repeats we get with this, your additions as you mention would be quite useful.

Thanks!
RJ