How to Upgrade Individual Packages in Ubuntu/CentOS

In this article, we'll dive deep and see how we can upgrade specific packages in Ubuntu/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 apt to upgrade specific packages in Ubuntu

To upgrade a specific package, login as root and run the command below

apt-get install --only-upgrade package-name

In the example below, we are going to upgrade apt

apt-get install --only-upgrade apt

Sample Output

# apt-get install --only-upgrade apt
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
  apt-utils libapt-pkg5.0
Suggested packages:
  aptitude | synaptic | wajig dpkg-dev apt-doc python-apt
The following packages will be upgraded:
  apt apt-utils libapt-pkg5.0
3 upgraded, 0 newly installed, 0 to remove and 49 not upgraded.
Need to get 1,945 kB of archives.
After this operation, 0 B of additional disk space will be used.
Do you want to continue? [Y/n]

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

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


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

yum versionlock httpd


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

Using Pacman to upgrade  specific packages in Archlinux

To update an individual package in ArchLinux using Pacman package manager, run the command below

pacman -S packagename

So for instance, if you run

pacman -S samba

The command will only update samba package only.

Read Also :

How to Exclude Specific Packages from Yum Update
How to Exclude Specific Package from apt-get Upgrade

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

Leave a Comment