How to Exclude Specific Packages from Yum Update
Abstract: 6 cloud-init.x86_64 0.7.9-9.el7_4.2 rhui-REGION-rhel-server-releases10 glibc.x86_64 2.17-196.el7_4.2 rhui-REGION-rhel-server-releases
In this article, we'll show you how to exclude specific packages from updating using Yum package manager. Periodically, you may want to update your CentOS or RHEL system but leave out certain packages especially if the updates are likely to interfere with certain major applications in the System.
Refer Also : How to Exclude Specific Package from apt-get Upgrade
Exclude Specific packages from updatingWe begin by first checking which packages are due for an upgrade using the Yum package manager on Centos 7, as shown below.
Disable Automatic Updates for cPane...To view this video please enable JavaScript, and consider upgrading to a web browser that supports HTML5 video
Disable Automatic Updates for cPanel | Turn-off Automatic Updates - Make Money Online Course Part 9yum list updates | cat -n
Sample Output
1 Loaded plugins: amazon-id, rhui-lb, search-disabled-repos
2 Updated Packages
3 bind-libs-lite.x86_64 32:9.9.4-51.el7_4.2 rhui-REGION-rhel-server-releases
4 bind-license.noarch 32:9.9.4-51.el7_4.2 rhui-REGION-rhel-server-releases
5 binutils.x86_64 2.25.1-32.base.el7_4.2 rhui-REGION-rhel-server-releases
6 cloud-init.x86_64 0.7.9-9.el7_4.2 rhui-REGION-rhel-server-releases
7 dhclient.x86_64 12:4.2.5-58.el7_4.1 rhui-REGION-rhel-server-releases
8 dhcp-common.x86_64 12:4.2.5-58.el7_4.1 rhui-REGION-rhel-server-releases
9 dhcp-libs.x86_64 12:4.2.5-58.el7_4.1 rhui-REGION-rhel-server-releases
10 glibc.x86_64 2.17-196.el7_4.2 rhui-REGION-rhel-server-releases
11 glibc-common.x86_64 2.17-196.el7_4.2 rhui-REGION-rhel-server-releases
12 initscripts.x86_64 9.49.39-1.el7_4.1 rhui-REGION-rhel-server-releases
13 iwl7265-firmware.noarch 22.0.7.0-58.el7_4 rhui-REGION-rhel-server-releases
14 kernel.x86_64 3.10.0-693.17.1.el7 rhui-REGION-rhel-server-releases
15 kernel-tools.x86_64 3.10.0-693.17.1.el7 rhui-REGION-rhel-server-releases
16 kernel-tools-libs.x86_64 3.10.0-693.17.1.el7 rhui-REGION-rhel-server-releases
To exclude a specific package from getting updated, the syntax would be as follows
yum --exclude=packagename\* update
For example, If you want to exclude package glibc which is 10th on our list, run
# yum --exclude=glibc\* update
Sample Output
Loaded plugins: amazon-id, rhui-lb, search-disabled-repos
Resolving Dependencies
--> Running transaction check
---> Package bind-libs-lite.x86_64 32:9.9.4-51.el7_4.1 will be updated
---> Package bind-libs-lite.x86_64 32:9.9.4-51.el7_4.2 will be an update
---> Package bind-license.noarch 32:9.9.4-51.el7_4.1 will be updated
---> Package bind-license.noarch 32:9.9.4-51.el7_4.2 will be an update
---> Package binutils.x86_64 0:2.25.1-32.base.el7_4.1 will be updated
---> Package binutils.x86_64 0:2.25.1-32.base.el7_4.2 will be an update
---> Package cloud-init.x86_64 0:0.7.9-9.el7_4.1 will be updated
---> Package cloud-init.x86_64 0:0.7.9-9.el7_4.2 will be an update
---> Package dhclient.x86_64 12:4.2.5-58.el7 will be updated
---> Package dhclient.x86_64 12:4.2.5-58.el7_4.1 will be an update
---> Package dhcp-common.x86_64 12:4.2.5-58.el7 will be updated
---> Package dhcp-common.x86_64 12:4.2.5-58.el7_4.1 will be an update
---> Package dhcp-libs.x86_64 12:4.2.5-58.el7 will be updated
---> Package dhcp-libs.x86_64 12:4.2.5-58.el7_4.1 will be an update
---> Package initscripts.x86_64 0:9.49.39-1.el7 will be updated
---> Package initscripts.x86_64 0:9.49.39-1.el7_4.1 will be an update
As you may have noted, package glibc is not on our list because we excluded it in our command.
To exclude a list of packages run
# yum --exclude=glibc\* --exclude=cloud-init\* update
Alternatively, you can use the command below to achieve the same purpose.
yum -x 'packagename*' update
To exclude more than one package using the same command, run the command below
yum -x 'packageName1*' -x 'packageName2*' update
Permanently disable specific packages from updating in Yum
To disable specific packages from getting updates open the following config file with a text editor of your choice
/etc/yum.conf
At the end of the config file, append the following
exclude=samba httpd mariadb php
The above excludes samba, httpd , MariaDB, PHP packages from updating.
To exclude 32 bit packages
exclude=*.i?86 *.i686
Now, if you try to update each of the individual packages, you'll get a prompt that "No packages marked for update"
Sample Output
[root@ip-172-31-16-136 ec2-user]# yum update httpd
Loaded plugins: amazon-id, rhui-lb, search-disabled-repos
rhui-REGION-client-config-server-7 | 2.9 kB 00:00:00
rhui-REGION-rhel-server-releases | 3.5 kB 00:00:00
rhui-REGION-rhel-server-rh-common | 3.8 kB 00:00:00
No packages marked for update
[root@ip-172-31-16-136 ec2-user]# yum update samba
Loaded plugins: amazon-id, rhui-lb, search-disabled-repos
No packages marked for update
[root@ip-172-31-16-136 ec2-user]# yum update mariadb
Loaded plugins: amazon-id, rhui-lb, search-disabled-repos
No packages marked for update
[root@ip-172-31-16-136 ec2-user]# yum update php
Loaded plugins: amazon-id, rhui-lb, search-disabled-repos
No packages marked for update
Exclude a repository from updating
Firstly, you may want to have a peek at the available repositories in your system. to achieve this, run the command below
yum repolist
Output
repo id repo name status
Webmin Webmin Distribution Neutral 111
base/7/x86_64 CentOS-7 - Base 9,591
epel/x86_64 Extra Packages for Enterprise Linux 7 - x86_64 12,382
extras/7/x86_64 CentOS-7 - Extras 392
filebeat/x86_64 Filebeat for ELK clients 44
google-chrome google-chrome 3
ius/x86_64 IUS Community Packages for Enterprise Linux 7 - x86_64 468
kibana-5.x Kibana repository for 5.x packages 338
logstash-5.x Elastic repository for 5.x packages 338
nux-dextop/x86_64 Nux.Ro RPMs for general desktop use 2,575
updates/7/x86_64 CentOS-7 - Updates 1,962
repolist: 28,204
To disable a repo from updating, we use the '--disablerepo=reponame' option alongside the yum update command.
yum --disablerepo=reponame update
Alternatively, the 'update' command can precede the 'disablerepo=reponame'option as shown
yum update -disablerepo=reponame
In the above example, If I want to disable kibana-5.x from updating, I'll run
yum --disablerepo=kibana-5.x update
To exclude multiple repositories in one line, separate the repositories using a comma as shown below
yum update--disablerepo=kibana-5.x,logstash-5.x
What this does is that it will update the rest of the repos but leave out kibana-5.x
Excluding a repository from updating using enabled parametersInstead of disabling the repo from updating in the yum update command, you can set the 'enabled' parameter to 0 in the repository configuration file.
The repo configuration file is located in /etc/yum.repos.d as shown
[root@epicenter ~]# ls -l /etc/yum.repos.d/
total 84
-rw-r--r--. 1 root root 1664 Aug 30 2017 CentOS-Base.repo
-rw-r--r--. 1 root root 1309 Aug 30 2017 CentOS-CR.repo
-rw-r--r--. 1 root root 649 Aug 30 2017 CentOS-Debuginfo.repo
-rw-r--r--. 1 root root 314 Aug 30 2017 CentOS-fasttrack.repo
-rw-r--r--. 1 root root 630 Aug 30 2017 CentOS-Media.repo
-rw-r--r--. 1 root root 1331 Aug 30 2017 CentOS-Sources.repo
-rw-r--r--. 1 root root 3830 Aug 30 2017 CentOS-Vault.repo
-rw-r--r-- 1 root root 390 Jan 28 20:05 decathorpe-elementary-stable-fedora-25.repo
-rw-r--r-- 1 root root 391 Jan 28 21:03 decathorpe-elementary-stable.repo
-rw-r--r-- 1 root root 951 Oct 2 20:44 epel.repo
-rw-r--r-- 1 root root 1050 Oct 2 20:44 epel-testing.repo
-rw-r--r--. 1 root root 178 Oct 4 13:01 filebeat.repo
-rw-r--r-- 1 root root 173 Jan 10 12:54 google-chrome.repo
-rw-r--r-- 1 root root 1150 Feb 23 2017 ius-archive.repo
-rw-r--r-- 1 root root 1131 Feb 23 2017 ius-dev.repo
-rw-r--r-- 1 root root 1073 Feb 23 2017 ius.repo
-rw-r--r-- 1 root root 1150 Feb 23 2017 ius-testing.repo
-rw-r--r--. 1 root root 212 Oct 3 12:05 kibana.repo
-rw-r--r--. 1 root root 216 Oct 3 14:01 logstash.repo
-rw-r--r-- 1 root root 477 Jul 31 2014 nux-dextop.repo
-rw-r--r--. 1 root root 163 Oct 3 11:23 webmin.repo
To exclude the kibana-5.x repository, open the configuration file using a text editor and set the 'enabled' option to 0 as shown below.
vim /etc/yum.repos.d/kibana.repo
If you run yum repolist, the repository will not show up in the results as shown
repo id repo name status
Webmin Webmin Distribution Neutral 111
base/7/x86_64 CentOS-7 - Base 9,591
epel/x86_64 Extra Packages for Enterprise Linux 7 - x86_64 12,382
extras/7/x86_64 CentOS-7 - Extras 392
filebeat/x86_64 Filebeat for ELK clients 44
google-chrome google-chrome 3
ius/x86_64 IUS Community Packages for Enterprise Linux 7 - x86_64 468
logstash-5.x Elastic repository for 5.x packages 338
nux-dextop/x86_64 Nux.Ro RPMs for general desktop use 2,575
updates/7/x86_64 CentOS-7 - Updates 1,962
repolist: 27,866
This implies that any packages from the kibana repo will not be updated when the yum update command is run.
Thank you for taking your time on this tutorial. We hope that we've addressed the issue on how you can disable specific packages in Yum. Free to give it a try and get back to us with your feedback.