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.
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 [mongodb-org-3.0] name=MongoDB Repository baseurl=http://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/3.0/x86_64/ gpgcheck=0 enabled=0
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.
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)