Question

How to disable repository from updates in Linux CentOS

I’m searching for a credible way to disable repositories and stop them from updating my packages. I’ve had some issue and found some ways on the internet but wanted to hear an opinion what’s best


Submit an answer


This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

KFSys
Site Moderator
Site Moderator badge
May 23, 2022
Accepted Answer

Hello,

There are a couple of ways to do so, depending on what you want to achieve.

If you now the exact repository you want to deny you can simply run:

  1. yum --disablerepo=Repo-Name

If you are not sure about the repo’s name, you can run:

  1. yum repolist

From there get the repo id.

There are other ways but is is the quickest I believe.

KFSys
Site Moderator
Site Moderator badge
August 28, 2023

If you’re using AlmaLinux 9, which is an RHEL fork like CentOS, the package manager in use is dnf (which replaced yum in recent RHEL-based distributions).

To disable a repository (or repositories) and stop them from updating your packages, you can follow these steps:

List Available Repositories

sudo dnf repolist

Disable a Repository

To disable a specific repository, you can use the dnf config-manager tool. If you don’t have it installed, install the dnf-plugins-core package:

sudo dnf install dnf-plugins-core

Now, to disable a repository, for instance epel, you would do:

sudo dnf config-manager --set-disabled epel

Replace epel with the name of the repository you wish to disable.

Temporary Disable During a Transaction

If you just want to temporarily exclude a repository during a specific dnf transaction, you can use the --disablerepo option. For example:

sudo dnf install some-package --disablerepo=epel

Permanent Disable via Configuration Files

Repositories have their configuration files located in /etc/yum.repos.d/. To disable a repository, you can edit its respective configuration file and set enabled=0.

For example, to disable the epel repository:

sudo nano /etc/yum.repos.d/epel.repo

Find the section for the repository and set:

enabled=0
KFSys
Site Moderator
Site Moderator badge
May 25, 2022

Hi @brendros,

Additionally, if you want to disable only a specific package from being updated, you can open and edit the yum.conf file, which is located in /etc/yum.conf or in /etc/yum/yum.conf. In the file if there isn’t a line exclude add one that way:

  1. exclude=php*

The above will disable all PHP packages from being updated.

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Get our biweekly newsletter

Sign up for Infrastructure as a Newsletter.

Hollie's Hub for Good

Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.

Become a contributor

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

Welcome to the developer cloud

DigitalOcean makes it simple to launch in the cloud and scale up as you grow — whether you're running one virtual machine or ten thousand.

Learn more
DigitalOcean Cloud Control Panel