disable package updates using yum/dnf

How to Disable Package Updates using YUM/DNF in RHEL, CentOS

Yum and Dnf and default package managers for RHEL, CentOS, Fedora, SUSE Linux. They are very useful in installing, upgrading and managing official packages on these Linux systems. But when we update our system, then these package managers will update almost every package on your system. This may end up breaking some of your existing packages in the process. So sometimes you may want to disable certain package updates using Yum/Dnf. In this article, we will learn how to disable package updates using Yum/Dnf in RHEL, CentOS, Fedora, SUSE Linux.


How to Disable Package Updates Using YUM/DNF in RHEL, CentOS

Here is the syntax to exclude package updates using Yum/Dnf.

exclude=package1 package2 packages*

In the above directive, you need to list packages to be excluded in a space-separated manner. In the above example, we will exclude package1, package2 and all packages beginning with ‘package’ string in their name.

You can add the above line in /etc/yum.cnf or /etc/dnf/dnf.cnf to exclude yum or dnf updates respectively.

Here are the steps to exclude packages.


1. Open Yum/Dnf configuration file

Open /etc/yum.cnf or /etc/dnf/dnf.cnf, depending on whether you want to disable updates from Yum or Dnf. If you want to disable updates from both, then repeat these steps for each of the mentioned files.

# vi /etc/yum.conf
OR
# vi /etc/dnf/dnf.conf


2. Exclude packages

For our example, we will exclude Apache (httpd), MySQL and PHP packages from updates so that it doesn’t break our website, during system updates. For this purpose, add the following line to the end of the opened file.

exclude=httpd php mysql

Save and close the file.


3. Test Configuration

Now we will test if the above packages have actually been excluded. We will do this by running an update command for apache server package.

# yum update httpd
OR
# dnf update httpd

You will see the following kind of output. The last line says that there are no packages to be updated, indicating that there are no updates for Apache package.

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


Alternatively, you can directly specify which packages to exclude, while running a system update command. Here is a command to exclude mysql and apache packages from system update.

# yum --exclude=httpd update
Or
# dnf --exclude=httpd update

You can also use wildcard character * with a backslash, to indicate a list of packages to be excluded.

# yum --exclude=mysql\* --exclude=httpd\* update
Or
# dnf --exclude=mysql\* --exclude=httpd\* update


Exclude Updates from EPEL Repository

Here are the steps to exclude package updates from EPEL repository.


1. Open EPEL configuration file

Open EPEL configuration file in a text editor.

# vi /etc/yum.repos.d/epel.repo


2. Exclude Packages

Add the following line to the bottom of open file, to exclude python, php, and perl.

exclude=perl php python

Save and close the file.


3. Test Configuration

Run the following command to test exclusion of above packages.

# dnf update perl php python
OR
# yum update perl php python

You will see the following kind of output, indicating that there are no updates pending.

Last metadata expiration check: 0:00:37 ago on Wednesday 15 December 2021 03:41:28 AM EST.
Package perl available, but not installed.
No match for argument: perl
No match for argument: php
No match for argument: python
Error: No packages marked for upgrade.

In this article, we have seen how to disable package updates in Yum/Dnf package managers. You can use these steps for almost every version or RHEL, CentOS, Fedora, SUSE Linux systems.

Also read:

How to Group By Multiple Columns in Python Pandas
How to Access Environment Variable in Python
How to Password Protect PDF File in Python
How to Read Inputs as Numbers in Python
How to Split Python Lists into Evenly Sized Chunks

Leave a Reply

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