In our previous article on the Linux yum command, we covered how we could use the yum package manager to search for packages, install them, query information about packages, check for security updates and update the system to have the latest versions of packages installed. In this article, we’ll show how to use yum to update/downgrade a single package, remove packages and a few other tips and tricks.
Update single package using YUM
Example 15: We could use yum to update a single or multiple packages instead of installing updates available for every package installed on the system. We accomplish this by using the yum update command followed by the package name.
Given below is an example.
[root@linuxnix ~]# yum update nfs-utils Loaded plugins: fastestmirror, refresh-packagekit, security Setting up Update Process Loading mirror speeds from cached hostfile * base: centos.mirror.snu.edu.in * epel: ftp.riken.jp * extras: centos.mirror.snu.edu.in * updates: centos.mirror.snu.edu.in Resolving Dependencies --> Running transaction check ---> Package nfs-utils.x86_64 1:1.2.3-70.el6 will be updated ---> Package nfs-utils.x86_64 1:1.2.3-75.el6_9 will be an update --> Finished Dependency Resolution Dependencies Resolved ============================================================ Package Arch Version Repository Size ============================================================ Updating: nfs-utils x86_64 1:1.2.3-75.el6_9 updates 336 k Transaction Summary ============================================================ Upgrade 1 Package(s) Total size: 336 k Is this ok [y/N]:
Remove a package using yum
Example 16: In order to remove a package from the system via yum, we use the yum remove command followed by the package name.
[root@linuxnix ~]# yum remove ncat Loaded plugins: fastestmirror, refresh-packagekit, security Setting up Remove Process Resolving Dependencies --> Running transaction check ---> Package ncat.x86_64 2:7.60-1 will be erased --> Finished Dependency Resolution Dependencies Resolved ========================================================== Package Arch Version Repository Size ========================================================== Removing: ncat x86_64 2:7.60-1 @/ncat-7.60-1.x86_64 2.8 M Transaction Summary ========================================================== Remove 1 Package(s) Installed size: 2.8 M Is this ok [y/N]:
In the above example, we removed the ncat package that we had installed earlier.
Note that removing packages will not work in case they are a dependency for another installed package.
Also, there are certain utilities which are critical to system function and are thereby protected from removal.
To demonstrate this, let’s try to remove yum using yum.
[root@linuxnix ~]# yum remove yum Loaded plugins: fastestmirror, refresh-packagekit, security Setting up Remove Process Resolving Dependencies --> Running transaction check ---> Package yum.noarch 0:3.2.29-73.el6.centos will be erased --> Processing Dependency: yum for package: python-meh-0.12.1-3.el6.noarch --> Processing Dependency: yum >= 3.0 for package: yum-plugin-fastestmirror-1.1.30-37.el6.noarch --> Processing Dependency: yum >= 3.2.19 for package: PackageKit-yum-0.5.8-26.el6.x86_64 --> Processing Dependency: yum >= 3.0 for package: PackageKit-yum-plugin-0.5.8-26.el6.x86_64 --> Processing Dependency: yum >= 3.2.18 for package: yum-plugin-security-1.1.30-37.el6.noarch --> Processing Dependency: yum >= 3.2.29-56 for package: yum-utils-1.1.30-37.el6.noarch --> Running transaction check ---> Package PackageKit-yum.x86_64 0:0.5.8-26.el6 will be erased --> Processing Dependency: PackageKit-yum = 0.5.8-26.el6 for package: PackageKit-0.5.8-26.el6.x86_64 ---> Package PackageKit-yum-plugin.x86_64 0:0.5.8-26.el6 will be erased ---> Package python-meh.noarch 0:0.12.1-3.el6 will be erased --> Processing Dependency: python-meh for package: firstboot-1.110.15-4.el6.x86_64 ---> Package yum-plugin-fastestmirror.noarch 0:1.1.30-37.el6 will be erased ---> Package yum-plugin-security.noarch 0:1.1.30-37.el6 will be erased ---> Package yum-utils.noarch 0:1.1.30-37.el6 will be erased --> Running transaction check ---> Package PackageKit.x86_64 0:0.5.8-26.el6 will be erased --> Processing Dependency: PackageKit >= 0.5.0 for package: gnome-packagekit-2.28.3-9.el6.x86_64 --> Processing Dependency: PackageKit = 0.5.8-26.el6 for package: PackageKit-glib-0.5.8-26.el6.x86_64 ---> Package firstboot.x86_64 0:1.110.15-4.el6 will be erased --> Running transaction check ---> Package PackageKit-glib.x86_64 0:0.5.8-26.el6 will be erased --> Processing Dependency: libpackagekit-glib2.so.12()(64bit) for package: PackageKit-gstreamer-plugin-0.5.8-26.el6.x86_64 --> Processing Dependency: PackageKit-glib = 0.5.8-26.el6 for package: PackageKit-gstreamer-plugin-0.5.8-26.el6.x86_64 --> Processing Dependency: PackageKit-glib = 0.5.8-26.el6 for package: PackageKit-gtk-module-0.5.8-26.el6.x86_64 --> Processing Dependency: PackageKit-glib = 0.5.8-26.el6 for package: PackageKit-device-rebind-0.5.8-26.el6.x86_64 ---> Package gnome-packagekit.x86_64 0:2.28.3-9.el6 will be erased --> Running transaction check ---> Package PackageKit-device-rebind.x86_64 0:0.5.8-26.el6 will be erased ---> Package PackageKit-gstreamer-plugin.x86_64 0:0.5.8-26.el6 will be erased ---> Package PackageKit-gtk-module.x86_64 0:0.5.8-26.el6 will be erased --> Finished Dependency Resolution Error: Trying to remove "yum", which is protected [root@linuxnix ~]#
Example 17: List enabled repositories
To list all enabled Yum repositories in your system, use the yum repolist command
[root@linuxnix ~]# yum repolist Loaded plugins: fastestmirror, refresh-packagekit, security Loading mirror speeds from cached hostfile * base: centos.mirror.snu.edu.in * epel: kartolo.sby.datautama.net.id * extras: centos.mirror.snu.edu.in * updates: centos.mirror.snu.edu.in repo id repo name status base CentOS-6 - Base 6,706 epel Extra Packages for Enterprise Linux 6 - x86_64 12,441 extras CentOS-6 - Extras 46 updates CentOS-6 - Updates 826 repolist: 20,019 [root@linuxnix ~]#
Example 18: List all repositories
To list both enabled and disabled yum repositories, use the yum repolist all command.
When installing packages, yum will not search for packages that are marked as disabled.
[root@linuxnix ~]# yum repolist all Loaded plugins: fastestmirror, refresh-packagekit, security Loading mirror speeds from cached hostfile * base: centos.mirror.snu.edu.in * epel: mirror.vinahost.vn * extras: centos.mirror.snu.edu.in * updates: centos.mirror.snu.edu.in repo id repo name status C6.0-base CentOS-6.0 - Base disabled C6.0-centosplus CentOS-6.0 - CentOSPlus disabled C6.0-contrib CentOS-6.0 - Contrib disabled C6.0-extras CentOS-6.0 - Extras disabled C6.0-updates CentOS-6.0 - Updates disabled C6.1-base CentOS-6.1 - Base disabled C6.1-centosplus CentOS-6.1 - CentOSPlus disabled C6.1-contrib CentOS-6.1 - Contrib disabled C6.1-extras CentOS-6.1 - Extras disabled C6.1-updates CentOS-6.1 - Updates disabled C6.2-base CentOS-6.2 - Base disabled C6.2-centosplus CentOS-6.2 - CentOSPlus disabled C6.2-contrib CentOS-6.2 - Contrib disabled C6.2-extras CentOS-6.2 - Extras disabled C6.2-updates CentOS-6.2 - Updates disabled C6.3-base CentOS-6.3 - Base disabled C6.3-centosplus CentOS-6.3 - CentOSPlus disabled C6.3-contrib CentOS-6.3 - Contrib disabled C6.3-extras CentOS-6.3 - Extras disabled C6.3-updates CentOS-6.3 - Updates disabled C6.4-base CentOS-6.4 - Base disabled C6.4-centosplus CentOS-6.4 - CentOSPlus disabled C6.4-contrib CentOS-6.4 - Contrib disabled C6.4-extras CentOS-6.4 - Extras disabled C6.4-updates CentOS-6.4 - Updates disabled C6.5-base CentOS-6.5 - Base disabled C6.5-centosplus CentOS-6.5 - CentOSPlus disabled C6.5-contrib CentOS-6.5 - Contrib disabled C6.5-extras CentOS-6.5 - Extras disabled C6.5-updates CentOS-6.5 - Updates disabled C6.6-base CentOS-6.6 - Base disabled C6.6-centosplus CentOS-6.6 - CentOSPlus disabled C6.6-contrib CentOS-6.6 - Contrib disabled C6.6-extras CentOS-6.6 - Extras disabled C6.6-updates CentOS-6.6 - Updates disabled base CentOS-6 - Base enabled: 6,706 base-debuginfo CentOS-6 - Debuginfo disabled c6-media CentOS-6 - Media disabled centosplus CentOS-6 - Plus disabled contrib CentOS-6 - Contrib disabled epel Extra Packages for Enterprise Linux 6 - x86_64 enabled: 12,441 epel-debuginfo Extra Packages for Enterprise Linux 6 - x86_64 - Debug disabled epel-source Extra Packages for Enterprise Linux 6 - x86_64 - Source disabled epel-testing Extra Packages for Enterprise Linux 6 - Testing - x86_64 disabled epel-testing-debuginfo Extra Packages for Enterprise Linux 6 - Testing - x86_64 - Debug disabled epel-testing-source Extra Packages for Enterprise Linux 6 - Testing - x86_64 - Source disabled extras CentOS-6 - Extras enabled: 46 fasttrack CentOS-6 - fasttrack disabled updates CentOS-6 - Updates enabled: 826 repolist: 20,019
Example 19: Clear the yum cache
By default yum keeps all the repository enabled package data in /var/cache/yum/.
This should be cleared regularly as the cached files are not very useful and end up consuming unnecessary storage space.
To clear the yum cache, you need to run the following command:
[root@linuxnix ~]# yum clean all Loaded plugins: fastestmirror, refresh-packagekit, security Cleaning repos: base epel extras updates Cleaning up Everything Cleaning up list of fastest mirrors [root@linuxnix ~]#
Example 20: Build yum cache
The yum package manager builds it’s cache periodically as we use yum to perform various software management tasks.
But we can rebuild the cache manually using the yum makecache command.
[root@linuxnix ~]# yum makecache Loaded plugins: fastestmirror, refresh-packagekit, security Determining fastest mirrors epel/metalink | 6.9 kB 00:00 * base: centos.mirror.net.in * epel: epel.mirror.net.in * extras: centos.mirror.net.in * updates: centos.mirror.net.in base | 3.7 kB 00:00 base/group_gz | 226 kB 00:02 base/filelists_db | 6.4 MB 01:21 base/primary_db | 4.7 MB 00:20 base/other_db | 2.8 MB 00:11 epel | 4.7 kB 00:00 epel/group_gz | 255 kB 00:00 epel/filelists_db | 7.8 MB 00:30 epel/updateinfo | 758 kB 00:03 epel/prestodelta | 326 B 00:00 epel/primary_db | 6.0 MB 00:25 epel/other_db | 3.0 MB 00:12 extras | 3.4 kB 00:00 extras/filelists_db | 25 kB 00:00 extras/prestodelta | 1.3 kB 00:00 extras/primary_db | 29 kB 00:00 extras/other_db | 30 kB 00:00 updates | 3.4 kB 00:00 updates/filelists_db | 3.2 MB 00:11 updates/prestodelta | 161 kB 00:00 updates/primary_db | 5.3 MB 00:21 http://centos.mirror.net.in/centos/6.9/updates/x86_64/repodata/20cf4f2f21960d99c164d71a6642b03759926fa64202164547e017885d9463ee-other.sqlite.bz2: [Errno 12] Timeout on http://centos.mirror.net.in/centos/6.9/updates/x86_64/repodata/20cf4f2f21960d99c164d71a6642b03759926fa64202164547e017885d9463ee-other.sqlite.bz2: (28, 'Operation too slow. Less than 1 bytes/sec transfered the last 30 seconds') Trying other mirror. updates/other_db | 75 MB 00:16 Metadata Cache Created [root@linuxnix ~]#
Example 21: Check yum database integrity
Yum maintains a database for all the package management tasks it performs.
To validate the integrity of this database we use the yum check command.
[root@linuxnix ~]# yum check Loaded plugins: fastestmirror, refresh-packagekit, security check all [root@linuxnix ~]#
Example 22: Assume yes
Up until now, whenever we’ve performed an action that would install/update/remove a package, yum asks us for confirmation.
This is a useful feature but could get tedious if we wish to script software modifications via yum.
to get around this we may use the -y option with the yum command to indicate a yes to whatever action we are trying to perform so that yum doesn’t prompt us for permission to proceed.
Example 23: Execute yum command in quite mode
Using yum can print a lot of output to the screen.
If you are not interested in viewing this output you can use the -q option with the yum command to make it run in a silent mode.
Here’s an example:
[root@linuxnix ~]# yum install nfs-utils -q -y [root@linuxnix ~]# echo $? 0 [root@linuxnix ~]#
Example 24: Enable verbose output
We can use the -v option with a yum command to enable more verbose output for the operation being performed.
In the below example, we will use the verbose option while we remove the nfs-utils package which we installed in the previous example.
[root@linuxnix ~]# yum remove nfs-utils -y -v Loading "fastestmirror" plugin Loading "refresh-packagekit" plugin Loading "security" plugin Config time: 0.019 Yum Version: 3.2.29 rpmdb time: 0.000 Setting up Remove Process Resolving Dependencies --> Running transaction check ---> Package nfs-utils.x86_64 1:1.2.3-75.el6_9 will be erased Checking deps for nfs-utils.x86_64 1:1.2.3-75.el6_9 - e ipa-client-3.0.0-50.el6.centos.1.x86_64 requires: nfs-utils --> Processing Dependency: nfs-utils for package: ipa-client-3.0.0-50.el6.centos.1.x86_64
Example 25: Downgrade a package
There may be circumstances such as a bug in the new version of a software or incompatibility with other installed software that may require us to downgrade a package.
To do this we use the yum downgrade option.
For this example, let’s downgrade the nfs-utils package.
First, we’ll check and verify the current version with yum list.
[root@linuxnix ~]# yum list nfs-utils Loaded plugins: fastestmirror, refresh-packagekit, security Loading mirror speeds from cached hostfile * base: centos.mirror.net.in * epel: epel.mirror.net.in * extras: centos.mirror.net.in * updates: centos.mirror.net.in Installed Packages nfs-utils.x86_64 1:1.2.3-75.el6_9 @updates [root@linuxnix ~]#
We see that version 1:1.2.3-75.el6_9 has been installed.
Now, let’s downgrade it.
[root@linuxnix ~]# yum downgrade nfs-utils Loaded plugins: fastestmirror, refresh-packagekit, security Setting up Downgrade Process Loading mirror speeds from cached hostfile * base: centos.mirror.net.in * epel: epel.mirror.net.in * extras: centos.mirror.net.in * updates: centos.mirror.net.in Resolving Dependencies --> Running transaction check ---> Package nfs-utils.x86_64 1:1.2.3-75.el6 will be a downgrade ---> Package nfs-utils.x86_64 1:1.2.3-75.el6_9 will be erased --> Finished Dependency Resolution Dependencies Resolved ==================================================================== Package Arch Version Repository Size ==================================================================== Downgrading: nfs-utils x86_64 1:1.2.3-75.el6 base 336 k
Transaction Summary ==================================================================== Downgrade 1 Package(s) Total download size: 336 k Is this ok [y/N]: y Downloading Packages: nfs-utils-1.2.3-75.el6.x86_64.rpm | 336 kB 00:01 Running rpm_check_debug Running Transaction Test Transaction Test Succeeded Running Transaction Installing : 1:nfs-utils-1.2.3-75.el6.x86_64 1/2 Cleanup : 1:nfs-utils-1.2.3-75.el6_9.x86_64 2/2 Verifying : 1:nfs-utils-1.2.3-75.el6.x86_64 1/2 Verifying : 1:nfs-utils-1.2.3-75.el6_9.x86_64 2/2 Removed: nfs-utils.x86_64 1:1.2.3-75.el6_9 Installed: nfs-utils.x86_64 1:1.2.3-75.el6 Complete!
Now let’s check the installed version of yum again:
[root@linuxnix ~]# yum list nfs-utils Loaded plugins: fastestmirror, refresh-packagekit, security Loading mirror speeds from cached hostfile * base: centos.mirror.net.in * epel: epel.mirror.net.in * extras: centos.mirror.net.in * updates: centos.mirror.net.in Installed Packages nfs-utils.x86_64 1:1.2.3-75.el6 @base Available Packages nfs-utils.x86_64 1:1.2.3-75.el6_9 updates [root@linuxnix ~]#
Observe that a lower version of the package is in the installed state and a higher version (which was installed earlier) is available for download.
Example 26: Omit strict dependency resolution
While you are trying to install or update a package yum will complain if it’s unable to meet all the dependency requirements of the selected software and will not complete the action.
In case you want to skip this check and proceed anyway use –skip-broken option.
Given below is a quick example:
[root@linuxnix ~]# yum --skip-broken update Loaded plugins: fastestmirror, refresh-packagekit, security Setting up Update Process Loading mirror speeds from cached hostfile * base: centos.mirror.net.in * epel: epel.mirror.net.in * extras: centos.mirror.net.in * updates: centos.mirror.net.in Resolving Dependencies --> Running transaction check ---> Package GConf2.x86_64 0:2.28.0-6.el6 will be updated ---> Package GConf2.x86_64 0:2.28.0-7.el6 will be an update ---> Package GConf2-gtk.x86_64 0:2.28.0-6.el6 will be updated ---> Package GConf2-gtk.x86_64 0:2.28.0-7.el6 will be an update ------------------------------------output truncated for brevity
Example 27: List packages not installed from a yum repository
To list packages that have not been installed from a yum repository, use the yum list extras command as shown below.
[root@linuxnix ~]# yum list extras Loaded plugins: fastestmirror, refresh-packagekit, security Loading mirror speeds from cached hostfile * base: centos.mirror.net.in * epel: epel.mirror.net.in * extras: centos.mirror.net.in * updates: centos.mirror.net.in Extra Packages GConf2.x86_64 2.28.0-6.el6 @anaconda-CentOS-201605220104.x86_64/6.8 GConf2-gtk.x86_64 2.28.0-6.el6 @anaconda-CentOS-201605220104.x86_64/6.8 NetworkManager.x86_64 1:0.8.1-107.el6 @anaconda-CentOS-201605220104.x86_64/6.8 NetworkManager-glib.x86_64 1:0.8.1-107.el6 @anaconda-CentOS-201605220104.x86_64/6.8 NetworkManager-gnome.x86_64 1:0.8.1-107.el6 @anaconda-CentOS-201605220104.x86_64/6.8 ORBit2.x86_64 2.14.17-5.el6 @anaconda-CentOS-201605220104.x86_64/6.8 abrt.x86_64 2.0.8-40.el6.centos @anaconda-CentOS-201605220104.x86_64/6.8 ----------------------------------------------------------output truncated for brevity
Note that it will list out all packages that were installed by the anaconda installer as well as the packages that were installed using yum localinstall.
Example 28: Using the interactive yum shell
Executing the yum shell command launches an interactive command line interface to the yum package manager.
This can be used to interactively execute yum command and if you specify file the yum commands in the file are executed if not you will get a shell to run yum commands.
[root@linuxnix ~]# yum shell Loaded plugins: fastestmirror, refresh-packagekit, security Setting up Yum Shell > info tree Loading mirror speeds from cached hostfile * base: centos.mirror.net.in * epel: epel.mirror.net.in * extras: centos.mirror.net.in * updates: centos.mirror.net.in Installed Packages Name : tree Arch : x86_64 Version : 1.5.3 Release : 3.el6 Size : 65 k Repo : installed From repo : base Summary : File system tree viewer URL : http://mama.indstate.edu/users/ice/tree/ License : GPLv2+ Description : The tree utility recursively displays the contents of directories in a : tree-like format. Tree is basically a UNIX port of the DOS tree : utility. > list openssh-server Installed Packages openssh-server.x86_64 5.3p1-117.el6 @anaconda-CentOS-201605220104.x86_64/6.8 Available Packages openssh-server.x86_64 5.3p1-123.el6_9 updates > exit Leaving Shell
Conclusion
This concludes our in-depth exploration of using the yum package management system in Linux.
There are a few other aspects of yum that we will writing separate posts for.
Sahil Suri
Latest posts by Sahil Suri (see all)
- Google Cloud basics: Activate Cloud Shell - May 19, 2021
- Create persistent swap partition on Azure Linux VM - May 18, 2021
- DNF, YUM and RPM package manager comparison - May 17, 2021
- Introduction to the aptitude package manager for Ubuntu - March 26, 2021
- zypper package management tool examples for managing packages on SUSE Linux - March 26, 2021