≡ Menu

How to Exclude a Specific Repository for Yum Update in CentOS / Red Hat

Q: I have multiple yum repositories on my system. For example, centos, epel, docker, mongo, etc. When I execute yum update command, installed packages from all the repositories are updated. How can I exclude a specific repository during yum update?

A: During yum update, to exclude packages that belongs to a specific repository, use any one of the two methods explained in this tutorial.

Also, keep in mind that instead of excluding a whole repository, you can also exclude a specific package: 10 Yum Exclude Examples to Skip Packages for Linux Yum Update (How to Yum Exclude Kernel Updates)

1. Get Repository List

To view all the available repositories on your system, execute yum repolist as shown below.

# yum repolist
repo id                repo name              status
base                   CentOS-6 - Base        6,575
extras                 CentOS-6 - Extras         62
updates                CentOS-6 - Updates     1,622
dockerrepo             Docker Repository          2
mongodb-org-3.0        MongoDB Repository        75
repolist: 8,336

In the above example, we have the following:

  • The first three repositories listed above are the main CentOS repositories: base, extras and updates
  • dockerrepo is a 3rd party repository that contains Docker container related packages
  • mongodb-org-3.0 is a 3rd party repository that contains MongoDB related packages.

When you do yum update as shown below, it will upgrade all the packages that are already installed on your system to the latest version available from all of the above repositories.

yum update

If you already have mongodb installed on your system, and when you execute the above “yum update”, it will also upgrade mongodb packages to the latest version.

If you don’t want to upgrade mongodb when you do “yum update”, you should exclude that during yum update as explained in the following section.

Also, if you want to know which repository a particular package belongs to, so that you can exclude that repository from getting upgraded, use yum info command as shown below.

yum info package-name | grep -i repo

If you are new to yum command: 15 Linux Yum Command Examples – Install, Uninstall, Update Packages

2. Exclude a Repository from Yum Update (Method 1)

You can use the option –disablerepo=repository-name along with yum update. This will not upgrade the packages that belongs to the given repository name.

In the following example, yum update will upgrade all installed packages except any installed packages that belongs to MongoDB repository.

yum --disablerepo=mongodb-org-3.0 update

You can also specify the –disablerepo option at the end after yum update. The following will exclude packages that belongs to Docker repository during yum update.

yum update --disablerepo=dockerrepo

You can get the exact repository name that you want to exclude by looking at the 1st column of the “yum repolist” command output.

3. Exclude a Repository from Yum Update using Enabled Parameter (Method 2)

Instead of excluding a specific repository from yum update command line, you can permanently exclude a package from yum update by setting the enabled parameter to 0 in the repository configuration file.

The repository configuration files are located under /etc/yum.repos.d directory as shown below.

# ls -l /etc/yum.repos.d/
-rw-r--r--. 1 root root 1926 Jan 30  2016 CentOS-Base.repo
-rw-r--r--  1 root root  166 Feb 18  2016 docker.repo
-rw-r--r--  1 root root  142 Feb  5  2016 mongodb-org-3.0.repo

To exclude mongodb repository, open the mongodb repository file, and set change the value of enabled to 0 as shown below.

# vi /etc/yum.repos.d/mongodb-org-3.0.repo 
name=MongoDB Repository

Now, if you do yum repolist, you’ll not see MongoDB repository in the output.

# yum repolist
repo id           repo name              status
base              CentOS-6 - Base        6,575
extras            CentOS-6 - Extras         62
updates           CentOS-6 - Updates     1,622
dockerrepo        Docker Repository          2
repolist: 8,261

This also means that even though you have mongodb related packages installed on your system, when you do the following “yum update”, mongodb packages will not be upgraded anymore.

yum update

4. Exclude Multiple Repositories from Yum update Command Line

You can also exclude multiple repositories during the yum update by specifying the repositories delimited by comma as shown below.

The following example will exclude MongoDB, Docker and EPEL repository during yum update.

yum update --disablerepo=mongodb-org-3.0,dockerrepo,epel

5. Enable a Repository for Yum Update

If you have disabled a repository by setting “enabled=0” in the repository configuration file, you can still include that during your “yum update” by using the –enablerepo option as shown below.

The following example will include the packages from MongoDB repository during “yum update” even though this repository is disabled in the repository file under /etc/yum.repos.d/ directory.

yum update --enablerepo=mongodb-org-3.0

6. Combine EnableRepo and DisableRepo in Yum Update

You can also get creative by combining enablerepo and disablerepo option.

For example, the following yum update command will upgrade only packages from MongoDB repository.

yum update --disablerepo=* --enablerepo=mongodb-org-3.0

In the above:

  • –disablerepo=* This indicates that all the repositories should first be disabled and not be considered for yum update
  • –enablerepo=mongo This indicates that only MongoDB repository should be considered during yum update (when combined with the above disable option)
Add your comment

If you enjoyed this article, you might also like..

  1. 50 Linux Sysadmin Tutorials
  2. 50 Most Frequently Used Linux Commands (With Examples)
  3. Top 25 Best Linux Performance Monitoring and Debugging Tools
  4. Mommy, I found it! – 15 Practical Linux Find Command Examples
  5. Linux 101 Hacks 2nd Edition eBook Linux 101 Hacks Book

Bash 101 Hacks Book Sed and Awk 101 Hacks Book Nagios Core 3 Book Vim 101 Hacks Book

Comments on this entry are closed.

  • Abhilash S V May 19, 2016, 12:46 am

    Hi Ramesh,

    I want to install apache2.4.18 on centos 7.1 which is not supporting the same version so how can i install the same version using YUM package?

    would be nice to share the good solution for this.


    Abhialsh S V