How to disable Certain Package Updates using YUM in CentOS
4 mins read

How to disable Certain Package Updates using YUM in CentOS

Description 

YUM means Yellowdog Updater Modified.

It is an open source default package management system for several Linux flavors like RHEL (Red Hat Enterprise Linux), CentOS (Community Enterprise Operating System)and Fedora.

The YUM utility is used to install, upgrade, remove rpm based packages from the distribution repositories in systems.

But sometime we don’t want to do update certain packages such as Apache Server (HTTP), MySQL, PHP and other major applications, because if such updates may harm currently running web application on server or you may stop updates till the application gets patched with new updates.

We can exclude or disable certain package updates from the any third party repositories. The exclude syntax would be as follow.

[root@vps ~]# exclude=package package1 packages*

The above syntax will exclude “package“, “package1” and list of “package” updates or installs.

Each keyword should be separated with space for exclusion of packages.

How to Exclude Packages in YUM

To exclude (disable) specific package updates, Open file called /etc/yum.conf with your choice of editor

[root@vps ~]# vi /etc/yum.conf

Add the following line at the bottom of the file with exclude keyword as shown below.

[main]
cachedir=/var/cache/yum/$basearch/$releasever
keepcache=0
debuglevel=2
logfile=/var/log/yum.log
exactarch=1
obsoletes=1
gpgcheck=1
plugins=1
installonly_limit=5
bugtracker_url=http://bugs.centos.org/set_project.php?project_id=16&ref=http://bugs.centos.org/bug_report_page.php?category=yum
distroverpkg=centos-release
# This is the default, if you make this bigger yum won't see if the metadata 
# is newer on the remote and so you'll "gain" the bandwidth of not having to
# download the new metadata and "pay" for it by yum not having correct
# information.
# It is esp. important, to have correct metadata, for distributions like
# Fedora which don't keep old packages around. If you don't like this checking
# interupting your command line usage, it's much better to have something
# manually check the metadata once an hour (yum-updatesd will do this).
# metadata_expire=90m
# PUT YOUR REPOS HERE OR IN separate files named file.repo
# in /etc/yum.repos.d
## Exclude following Packages Updates ##
exclude=httpd php mysql

In the above example, the line exclude will disable updates for “httpd” “php” and “mysql” packages.

Let’s try installing or updating one of them using YUM command as shown below.

[root@vps ~]# yum update httpd

Sample Output

Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: centos.01link.hk
* extras: centos.01link.hk
* updates: mirrors.hns.net.in
base | 3.7 kB 00:00
extras | 3.0 kB 00:00
updates | 3.5 kB 00:00
updates/primary_db | 2.7 MB 00:16
Setting up Update Process
No Packages marked for Update

How to Exclude Packages from EPEL Repo 

To exclude packages installs or updates from EPEL repository, then open the file called /etc/yum.repos.d/epel.repo.

[root@vps ~]# vi /etc/yum.repos.d/epel.repo

Add the exclude line by specifying packages to be exclude from the updates.

[epel]
name=Extra Packages for Enterprise Linux 6 - $basearch
#baseurl=http://download.fedoraproject.org/pub/epel/6/$basearch
mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-6&arch=$basearch
failovermethod=priority
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6
## Exclude following Packages Updates ##
exclude=perl php python

Now try to update above specified files from the EPEL repository using YUM command.

[root@vps ~]# yum --enablerepo=epel update perl php python

Sample Output 

Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.hns.net.in
* epel: ftp.kddilabs.jp
* extras: mirrors.hns.net.in
* updates: mirrors.hns.net.in
Setting up Update Process
No Packages marked for Update

You can also use yum command line option to exclude package without adding to the repository files.

[root@vps ~]# yum --exclude=httpd update

To exclude list of packages, use the command as follows.

[root@vps ~]# yum --exclude=mysql\* --exclude=httpd\* update

We hope you’ve found this useful!

Leave a Reply

Your email address will not be published. Required fields are marked *