When you perform yum update, it will download the latest version of all the packages that are installed on your system, and upgrade them to the latest version.
You may be in situation where you might not want yum to automatically update one (or more) specific package.
In those situations, use the yum exclude option as shown in the examples below.
1. Exclude a Single Package using option -x
For example, on this system, we are using PHP 5.1, and the custom php application running on this system is not tested with any other new versions of PHP yet.
# rpm -q php php-5.1.0-27.el6_5.x86_64
So, in this case when we do a update, we want to exclude only one specific package, which is php. As we see below, the following indicates that php package will be updated to ver 5.3.3 when we perform the ‘yum update’ command.
# yum check-update php php.x86_64 5.3.3-40.el6_6 updates
The following will exclude only one package (php) during the yum update.
# yum -x php update
2. Exclude Multiple Packages using option -x
You can exclude multiple packages by specifying multiple -x options as shown below:
yum -x php -x httpd update
You can also exclude more than one package by specifying the list of packages separated by comma. The following will behave exactly same as above.
yum -x php,httpd update
3. Exclude Multiple Packages (e.g. Kernel packages) using Wildcard
In most situations you might not want yum update to automatically upgrade the kernel.
Before you do the real yum update, you can perform yum check-update, which will display all the packages that it will upgrade during the yum update.
As you see below, in this example, there are three kernel related packages that will be upgraded by yum update.
# yum check-update | grep -i kernel kernel.x86_64 2.6.32-504.1.3.el6 updates kernel-firmware.noarch 2.6.32-504.1.3.el6 updates kernel-headers.x86_64 2.6.32-504.1.3.el6 updates
Instead of specifying all the individual package names in the -x exclude list, we can simply use the shell glob wildcards as shown below. The following will exclude all kernel related packages form begin upgraded during the yum update.
yum -x kernel* update
4. Multiple Wildcard Lists in the -x Option
You can also specify multiple wildcard lists in the -x option.
As you see below, the following indicates that there are multiple php packages that will be upgraded during next yum update.
# yum check-update | grep -i php php.x86_64 5.3.3-40.el6_6 updates php-cli.x86_64 5.3.3-40.el6_6 updates php-common.x86_64 5.3.3-40.el6_6 updates php-xml.x86_64 5.3.3-40.el6_6 updates
If you want to exclude all php and kernel related packages during the next yum update, you can use the following. Please note that you should use ‘ ‘ in this example.
yum -x 'php*' -x 'kernel*' update
5. Using –exclude instead of -x
You can also use –exclude instead of -x as shown below:
yum --exclude php update yum --exclude httpd update yum --exclude kernel update yum -exclude php*,httpd*,kernel* update
6. Exclude Packages Using yum.conf File
Instead of specifying the packages to be excluded in the command line, you can specify them in the /etc/yum.conf file.
For example, to exclude all the php, httpd and kernel packages to be excluded from the yum update, add the following line:
exclude=php* httpd* kernel*
Or, execute the following command:
echo "exclude=php* httpd* kernel*" >> /etc/yum.conf
7. Use Comma Separated List
You can also exclude more than one package by specifying the list of wildcard packages separated by comma. The following will behave exactly same as above.
yum -x php*,kernel* update
To be consistent with the way how we showed the other examples using the -x option above, you can also use comma (instead of just space) to separate the multiple packages as shown below:
# vi /etc/yum.conf exclude=php*,httpd*,kernel*
8. Exclude Parameter inside Custom Repo File
Instead of specifying the exclude parameter in the main yum.conf file, you can also specify it in the individual repository file.
For example, if you’ave installed mongodb, you’ll have mongodb.repo under /etc/yum.repos.d directory. You can specify the exclude package list for the mongodb repository inside this mongodb.repo file.
# vi /etc/yum.repos.d/mongodb.repo exclude=mongo*
9. Simulate Yum Exclude Check using check-update (Dry-run -x)
You can specify the -x option along with check-update also. This helps to you check whether the -x option you’ve specified either in the command line or in the yum.conf file is working as expected.
For example, the following indicates that the kernel will be upgraded during yum update.
# yum check-update | grep -i kernel kernel.x86_64 2.6.32-504.1.3.el6 updates kernel-firmware.noarch 2.6.32-504.1.3.el6 updates kernel-headers.x86_64 2.6.32-504.1.3.el6 updates
The following indicates that the -x flag will work as expected as it didn’t return anything in the result.
# yum -x kernel* check-update | grep -i kernel
For example, let us say the following exclude line in present in the yum.conf file.
# grep exclude /etc/yum.conf exclude=php*,httpd*,kernel*
Then, the following indicates that the exclude list specified in the above /etc/yum.conf will work as expected as check-update didn’t show those packages (including kernel) in the following output.
# yum check-update | egrep 'php|httpd|kernel'
10. Ignore the Exclude from yum.conf File
If you like to disable the excludes mentioned in the yum.conf file. i.e If you don’t want yum update to consider the exclude list that is specified in the yum.conf file, you can use the –disableexcludes option from the command line.
In our previous example, we’ve excluded php, httpd and kernel packages to be updated by the yum update.
But, if you want yum to ignore that exclude list (i.e disable the exclude) and continue to upgrade the php, httpd and kernel as part of the regular yum update command, execute the following:
yum --disableexcludes=all update
The following are the three possible values that you can specify to the disableexcludes
- all Disable all excludes
- main Disable excludes specified in the main section of the yum.conf file
- repoid Disable excludes specified for the given repo id
If you want to disable the excludes only for a specific custom repository, you can specify the repo id (which is the 1st column in the yum repolist command as shown below).
# yum repolist repo id repo name status mongodb MongoDB Repository 240 base CentOS-6 - Base 6,518 extras CentOS-6 - Extras 35 updates CentOS-6 - Updates 315
The following will disable (ignore) the exclude list specified in the mongodb.repo file under /etc/yum.repos.d directory.
yum --disableexcludes=mongodb update
Comments on this entry are closed.
Nice stuff…
Nice stuff…
Very instructive – Thanks!