How to Upgrade Individual Packages in CentOS

In this article, we'll dive deep and see how we can upgrade specific packages on CentOS distributions. Once in a while, you may be required to upgrade certain packages and leave others in their default versions. One reason for this is maintaining the stability of packages that are used in running crucial services such as databases and web servers. Sometimes an upgrade may result in changes in the package that may affect the normal running of services.

Using yum to upgrade specific packages in CentOS

Before anything else, we may need first to check the packages with pending updates. To do this, run the following command

yum list updates

You may need to display multiple versions of a package that exists in your system. To do this, run the command below

yum --showduplicates list httpd | expand

In the above example, you'll be displaying multiple versions of httpd package.

 Installed Packages
httpd.x86_64         2.4.6-67.el7_4.6          @rhui-REGION-rhel-server-releases
Available Packages
httpd.x86_64         2.4.6-17.el7              rhui-REGION-rhel-server-releases
httpd.x86_64         2.4.6-18.el7_0            rhui-REGION-rhel-server-releases
httpd.x86_64         2.4.6-19.el7_0            rhui-REGION-rhel-server-releases
httpd.x86_64         2.4.6-31.el7              rhui-REGION-rhel-server-releases
httpd.x86_64         2.4.6-31.el7_1.1          rhui-REGION-rhel-server-releases
httpd.x86_64         2.4.6-40.el7              rhui-REGION-rhel-server-releases
httpd.x86_64         2.4.6-40.el7_2.1          rhui-REGION-rhel-server-releases
httpd.x86_64         2.4.6-40.el7_2.4          rhui-REGION-rhel-server-releases
httpd.x86_64         2.4.6-45.el7              rhui-REGION-rhel-server-releases
httpd.x86_64         2.4.6-45.el7_3.4          rhui-REGION-rhel-server-releases
httpd.x86_64         2.4.6-67.el7              rhui-REGION-rhel-server-releases
httpd.x86_64         2.4.6-67.el7_4.2          rhui-REGION-rhel-server-releases
httpd.x86_64         2.4.6-67.el7_4.5          rhui-REGION-rhel-server-releases
httpd.x86_64         2.4.6-67.el7_4.6          rhui-REGION-rhel-server-releases

From the results above, we notice that the httpd package currently installed is version 2.4.6-67.el7_4.6 which is the latest. What if you wanted to install a specific version of the package, how would you go about it? The syntax for that will be as shown below

yum install packagename version

For example, If you desire to downgrade to version 2.4.6-67.el7_4.5, you'll need to remove the latest version first as shown.

yum remove httpd

Thereafter, install your preferred httpd version as shown.

yum install httpd 2.4.6-67.el7_4.5

To lock the version of the package we've installed, to avert any future updates, we use the versionlock plugin. To install the plugin, run

yum install yum-versionlock

Sample Output

yum-plugin-versionlock-1.1.31-42.el7.noarch.rpm                                                                                                  |  32 kB  00:00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : yum-plugin-versionlock-1.1.31-42.el7.noarch                                                                                                          1/1
  Verifying  : yum-plugin-versionlock-1.1.31-42.el7.noarch                                                                                                          1/1

Installed:
  yum-plugin-versionlock.noarch 0:1.1.31-42.el7

Complete!

To lock our httpd package version, we'll run the command below

yum versionlock httpd

Output

Loaded plugins: amazon-id, rhui-lb, search-disabled-repos, versionlock
Adding versionlock on: 0:httpd-2.4.6-67.el7_4.5  
versionlock added: 1

To upgrade specific packages

yum upgrade package-name

To temporarily exclude a package from an upgrade, run the following command

yum --exclude update package-name

Alternatively, you can use the -x flag instead of --exclude

yum -x exclude httpd,php

The above command will exclude the httpd and php packages from the upgrade as the rest of the packages are upgraded.

If you want to permanently disable a package from updates, locate the yum.conf in /etc/yum/yum.conf

Here's a snap of how it looks like

disable specific packages in ubuntu/centos

To exclude a package, append exclude=package-nameat the end of the configuration file. In this example, we'll exclude samba , httpd, php and mariadb packages from the upgrade as shown below.

exclude specific packages from upgrade
If you try to upgrade either of there packages, you'll get an No packages marked for update error.

disable specific packages from upgrade

Related Read:

You are welcome to try out the commands. Your feedback is highly welcome. Thank you.

Leave a Comment