Force yum update Command To Exclude Certain Packages

How can I exclude selected packages when I rum yum update command under CentOS / RHEL / Fedora / Red Hat Enterprise Linux server?

Yum uses a configuration file at /etc/yum/yum.conf or /etc/yum.conf. You need to place exclude directive to define list of packages to exclude from updates or installs. This should be a space separated list. Shell globs using wildcards * and ?) are allowed.

How do I exclude php and kernel packages when I use “yum update”?

Open /etc/yum.conf file, enter:
# vi /etc/yum.conf
Append the following line under [main] section, enter:
exclude=php* kernel*
At the end, it should look like as follows:

[main]
cachedir=/var/cache/yum
keepcache=0
debuglevel=2
logfile=/var/log/yum.log
distroverpkg=redhat-release
tolerant=1
exactarch=1
obsoletes=1
gpgcheck=1
plugins=1
exclude=php* kernel*
 
# Note: yum-RHN-plugin doesn't honor this.
metadata_expire=1h
 
# Default.
# installonly_limit = 3
 
# PUT YOUR REPOS HERE OR IN separate files named file.repo
# in /etc/yum.repos.d

[main]
cachedir=/var/cache/yum
keepcache=0
debuglevel=2
logfile=/var/log/yum.log
distroverpkg=redhat-release
tolerant=1
exactarch=1
obsoletes=1
gpgcheck=1
plugins=1
exclude=php* kernel* # Note: yum-RHN-plugin doesn’t honor this.
metadata_expire=1h # Default.
# installonly_limit = 3 # PUT YOUR REPOS HERE OR IN separate files named file.repo
# in /etc/yum.repos.d

Save and close the file. You can now use the yum command as usual but certain package will not install.

How Do I Disable Excludes?

You can use the following syntax:

yum --disableexcludes=all update
yum --disableexcludes=main install php
yum --disableexcludes=repoid install php httpd

yum –disableexcludes=all update
yum –disableexcludes=main install php
yum –disableexcludes=repoid install php httpd

Where,

  1. all : Disable all excludes
  2. main : Disable excludes defined in [main] in yum.conf
  3. repoid : Disable excludes defined for given repo id

yum –exclude Command Line Option

Finally, you can skip yum command updates on command line itself using following syntax:
# yum --exclude=package* update
# yum --exclude=php* update
# yum --exclude=kernel* update
# yum -x 'kernel*' -x 'php*' update

Note: The above syntax will exclude a specific package by name or glob from updates on all repositories.

Recommend readings:

For more information view the manual page on yum command using the following command:
$ man yum
$ man yum.conf

Posted by: SXI ADMIN

The author is the creator of SXI LLC and a seasoned sysadmin, DevOps engineer, and a trainer for the Linux operating system/Unix shell scripting. Get the latest tutorials on SysAdmin, Linux/Unix and open source topics via RSS/XML feed or weekly email newsletter.