Introduction
For managing software via the command line on our Redhat and Centos systems, we could use rpm directly or use yum which is somewhat of a feature rich front end for rpm.
We covered the Linux rpm command and it’s features extensively in an earlier article.
Yum is an acronym for yollowdog updater modified. The name yellowdog comes from a distribution of Linux which was focussed on IBMs’ power line of systems in the early 2000s.
The yum package manager is an earlier implementation of yep, the package manager used by yellowdog Linux.
Yum sitting on top of rpm is the default package management interface for Redhat and Centos systems and older versions of Fedora.
After Fedora 22 onwards, yum was switched in favor of dnf and we will cover dnf in a future post.
The major advantage of using yum over rpm is that yum manages dependencies for packages automatically.
So if a package requires python or ruby or any other package then yum will go out and fetch and install these packages and any other dependencies which are needed by the package that we are trying to install.
If you are trying to install a package that has dependencies via rpm, then you need to be aware of those dependencies and have the rpm package files for those dependencies available and installed on the system.
We need to provide the exact package file name to install it via rpm. Yum allows us to work on a higher level.
With yum we don’t need to search the web for the exact package file names.
Yum provides us tools to search for packages and install them, all from the command line.
The yum tool searches for packages and their dependencies in large collections of packages called repositories, on the network.
Yum maintains a local cache of repository data so that you could query information from the repository even when you are offline.
to access the yum command line interface we use the yum command.
In this article, we will share some of the most useful and frequently used options with the yum command.
Example 1: Search for a package
For the first example, we’ll show you how to look for packages using yum.
To search for a package we use the yum search command followed by the search term.
let’s search for the awk package
[root@linuxnix ~]# yum search awk Loaded plugins: fastestmirror, refresh-packagekit, security Loading mirror speeds from cached hostfile * base: centos.mirror.snu.edu.in * epel: mirror.rise.ph * extras: centos.mirror.snu.edu.in * updates: centos.mirror.snu.edu.in ============================================================================================== N/S Matched: awk ============================================================================================== fawkes-core.i686 : Fawkes base system fawkes-core.x86_64 : Fawkes base system fawkes-devel.i686 : Development files for Fawkes fawkes-devel.x86_64 : Development files for Fawkes fawkes-devenv.noarch : Development environment Fawkes fawkes-doc.noarch : Fawkes API documentation fawkes-guis.i686 : GUI applications to control Fawkes fawkes-guis.x86_64 : GUI applications to control Fawkes fawkes-lua.i686 : Lua libraries and scripts for Fawkes fawkes-lua.x86_64 : Lua libraries and scripts for Fawkes fawkes-plugin-bblogger.x86_64 : Fawkes plugin to log data from blackboard fawkes-plugin-bbsync.x86_64 : Fawkes plugin to synchronize multiple instances fawkes-plugin-flite.x86_64 : Fawkes Flite speech synthesis plugin fawkes-plugin-joystick.x86_64 : Fawkes plugin to access joysticks fawkes-plugin-katana.x86_64 : Fawkes plugin to control the Katana robot arm fawkes-plugin-laser.x86_64 : Fawkes plugin to access laser range finders fawkes-plugin-pantilt.x86_64 : Fawkes plugin to control pan-tilt units fawkes-plugin-skiller.i686 : Fawkes behavior engine plugin fawkes-plugin-skiller.x86_64 : Fawkes behavior engine plugin fawkes-plugin-webview.x86_64 : Fawkes plugin to provide a web interface gawk.x86_64 : The GNU version of the awk text processing utility mawk.x86_64 : Interpreter for the AWK programming language nawk.x86_64 : "The one true awk" descended from UNIX V7 nodejs-hawk.noarch : HTTP Hawk authentication scheme fawkes.x86_64 : Robot Software Framework fawkes-firevision.i686 : Computer vision sub-system fawkes-firevision.x86_64 : Computer vision sub-system fawkes-firevision-tools.x86_64 : Computer vision sub-system tools fawkes-plugin-laserht.x86_64 : Line detection in laser data using Hough Transform fawkes-plugin-luaagent.x86_64 : Agent framework written in Lua fawkes-plugin-refboxcomm.x86_64 : RoboCup referee box integration fawkes-plugin-ttmainloop.x86_64 : Time tracking main loop fawkes-plugin-worldmodel.x86_64 : World model to concentrate information fex.x86_64 : Field split/extraction like cut/awk Name and summary matches only, use "search all" for everything. [root@linuxnix ~]#
The yum search command will search for the search term in the package name and description.
So, it will match if the search term appears as a package name, part of a package name or in the description as is evident from the search results displayed in the example.
You usually don’t need to use wildcards while searching for packages with yum.
Example 2: Check which package provides a file/command
Another frequent requirement is to check which package provides a particular file or executable.
We can use the yum provides the command with the file name to find out the name of the package which provides that file.
[root@linuxnix ~]# yum provides /usr/bin/ssh 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 openssh-clients-5.3p1-122.el6.x86_64 : An open source SSH client applications Repo : base Matched from: Filename : /usr/bin/ssh openssh-clients-5.3p1-123.el6_9.x86_64 : An open source SSH client applications Repo : updates Matched from: Filename : /usr/bin/ssh openssh-clients-5.3p1-117.el6.x86_64 : An open source SSH client applications Repo : installed Matched from: Other : Provides-match: /usr/bin/ssh
The yum provides tells us the name of the package which provides the file name and the repository in which the package can be found.
You don’t need to provide the full path of the command you wish to search for.
to demonstrate this, let’s search for the ansible command, which is not installed on the system:
[root@linuxnix ~]# yum provides ansible Loaded plugins: fastestmirror, refresh-packagekit, security Loading mirror speeds from cached hostfile * base: centos.mirror.snu.edu.in * epel: repo.ugm.ac.id * extras: centos.mirror.snu.edu.in * updates: centos.mirror.snu.edu.in ansible-2.4.1.0-2.el6.noarch : SSH-based configuration management, deployment, and task execution system Repo : epel
Example 3: Install a package
The easiest way to install a package in Linux is through yum.
When we use yum to install a package it will search for the package in all the available repositories, resolve it’s dependencies and install them.
It will do all that in a single command i.e. yum install followed by the name of the package we would like to install.
In the below example we will use yum to install a package named tree.
[root@linuxnix ~]# yum install tree Loaded plugins: fastestmirror, refresh-packagekit, security Setting up Install Process Loading mirror speeds from cached hostfile * base: centos.mirror.snu.edu.in * epel: repo.ugm.ac.id * extras: centos.mirror.snu.edu.in * updates: centos.mirror.snu.edu.in Resolving Dependencies --> Running transaction check ---> Package tree.x86_64 0:1.5.3-3.el6 will be installed --> Finished Dependency Resolution Dependencies Resolved ==================================================================================== Package Arch Version Repository Size ==================================================================================== Installing: tree x86_64 1.5.3-3.el6 base 36 k Transaction Summary ================================================================================ Install 1 Package(s) Total download size: 36 k Installed size: 65 k Is this ok [y/N]: y Downloading Packages: tree-1.5.3-3.el6.x86_64.rpm | 36 kB 00:00 Running rpm_check_debug Running Transaction Test Transaction Test Succeeded Running Transaction Warning: RPMDB altered outside of yum. Installing : tree-1.5.3-3.el6.x86_64 1/1 Verifying : tree-1.5.3-3.el6.x86_64 1/1 Installed: tree.x86_64 0:1.5.3-3.el6 Complete!
Note: A very useful feature of yum is that it will only search for and install packages compatible with your machine architecture and OS version.
We need not be concerned with that aspect of package management when we are using yum.
Example 4: Download a package without installing
In the previous example, we showed you how to use yum to install a package.
But if we just needed to download the package and not install it immediately.
This requirement can be fulfilled by using the –downloadonly option with the yum install command as we’ll see in the below example:
[root@linuxnix ~]# yum install --downloadonly nfs-utils Loaded plugins: fastestmirror, refresh-packagekit, security Setting up Install 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 download size: 336 k Is this ok [y/N]: y Downloading Packages: nfs-utils-1.2.3-75.el6_9.x86_64.rpm | 336 kB 00:02 exiting because --downloadonly specified
The above command successfully downloaded the package on to our system.
But the package was not downloaded to the present working directory.
The location of the downloaded package is /var/cache/yum/x86_64/6/updates/packages/ with updates reflecting the name of the repository from which the package was downloaded.
[root@linuxnix ~]# ls -ltr /var/cache/yum/x86_64/6/updates/packages/nfs-utils-1.2.3-75.el6_9.x86_64.rpm -rw-r--r--. 1 root root 344028 Nov 15 23:53 /var/cache/yum/x86_64/6/updates/packages/nfs-utils-1.2.3-75.el6_9.x86_64.rpm [root@linuxnix ~]#
You could specify a different download location using the –downloaddir option. Just type –downloaddir=<destination directory path>
Example 5: Get information about a package
We can use yum to query the repositories for information about a package using the yum info command.
Let’s query information for the nfs-utils package we downloaded earlier:
[root@linuxnix ~]# yum info nfs-utils 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 Installed Packages Name : nfs-utils Arch : x86_64 Epoch : 1 Version : 1.2.3 Release : 70.el6 Size : 1.0 M Repo : installed From repo : anaconda-CentOS-201605220104.x86_64 Summary : NFS utilities and supporting clients and daemons for the kernel NFS server URL : http://sourceforge.net/projects/nfs License : MIT and GPLv2 and GPLv2+ and BSD Description : The nfs-utils package provides a daemon for the kernel NFS server and : related tools, which provides a much higher level of performance than the : traditional Linux NFS server used by most users. : : This package also contains the showmount program. Showmount queries the : mount daemon on a remote host for information about the NFS (Network File : System) server on the remote host. For example, showmount can display the : clients which are mounted on that host. : This package also contains the mount.nfs and umount.nfs program. Available Packages Name : nfs-utils Arch : x86_64 Epoch : 1 Version : 1.2.3 Release : 75.el6_9 Size : 336 k Repo : updates Summary : NFS utilities and supporting clients and daemons for the kernel NFS server URL : http://sourceforge.net/projects/nfs License : MIT and GPLv2 and GPLv2+ and BSD Description : The nfs-utils package provides a daemon for the kernel NFS server and : related tools, which provides a much higher level of performance than the : traditional Linux NFS server used by most users. : This package also contains the showmount program. Showmount queries the : mount daemon on a remote host for information about the NFS (Network File : System) server on the remote host. For example, showmount can display the : clients which are mounted on that host. : This package also contains the mount.nfs and umount.nfs program. [root@linuxnix ~]#
As you may observe from the above output, yum info will work for packages that are installed or not in an installed state.
Example 6: Check dependencies for a package
We can check for dependencies of a package using yum deplist command.
In the below example we will take a look at the dependencies for the openssh-server package.
[root@linuxnix ~]# yum deplist openssh-server Loaded plugins: fastestmirror, refresh-packagekit, security Finding dependencies: 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 package: openssh-server.x86_64 5.3p1-122.el6 dependency: pam >= 1.0.1-3 provider: pam.x86_64 1.1.1-24.el6 provider: pam.i686 1.1.1-24.el6 dependency: libc.so.6(GLIBC_2.8)(64bit) provider: glibc.x86_64 2.12-1.209.el6 provider: glibc.x86_64 2.12-1.209.el6_9.1 provider: glibc.x86_64 2.12-1.209.el6_9.2 dependency: libcrypt.so.1(GLIBC_2.2.5)(64bit) provider: glibc.x86_64 2.12-1.209.el6 provider: glibc.x86_64 2.12-1.209.el6_9.1 provider: glibc.x86_64 2.12-1.209.el6_9.2 dependency: libnss3.so(NSS_3.2)(64bit) provider: nss.x86_64 3.27.1-13.el6 provider: nss.x86_64 3.28.3-3.el6_9 provider: nss.x86_64 3.28.4-1.el6_9 provider: nss.x86_64 3.28.4-3.el6_9 provider: nss.x86_64 3.28.4-4.el6_9 ---------output truncated for brevity
The above output accurately lists out what (dependency) the package requires and what (provider) fulfills those requirements.
This is similar to using the rpm command with the -qR option for an rpm package file.
Example 7: Check if a package is installed
We can easily use yum to check if a package is installed on the system using the yum list command followed by the package name.
[root@linuxnix ~]# yum list openssh-server 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 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 [root@linuxnix ~]#
The above output shows that a version of the openssh-server package is installed on the server and an updated version is available.
Example 8: Install a locally downloaded package
We can use the yum localinstall command to install any locally downloaded packages.
In this case yum uses the locally available rpm package file to install the software and then goes out and searches for any dependencies that the package might have in repositories if the system is online.
Here is an example of installing a locally downloaded rpm named ncat using yum localinstall.
[root@linuxnix ~]# yum localinstall ncat-7.60-1.x86_64.rpm Loaded plugins: fastestmirror, refresh-packagekit, security Setting up Local Package Process Examining ncat-7.60-1.x86_64.rpm: 2:ncat-7.60-1.x86_64 Marking ncat-7.60-1.x86_64.rpm to be installed 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 Resolving Dependencies --> Running transaction check ---> Package ncat.x86_64 2:7.60-1 will be installed --> Finished Dependency Resolution Dependencies Resolved ============================================================================================================================================================================================================== Package Arch Version Repository Size ============================================================================================================================================================================================================== Installing: ncat x86_64 2:7.60-1 /ncat-7.60-1.x86_64 2.8 M Transaction Summary ================================================================================ Install 1 Package(s) Total size: 2.8 M Installed size: 2.8 M Is this ok [y/N]: y Downloading Packages: Running rpm_check_debug Running Transaction Test Transaction Test Succeeded Running Transaction Warning: RPMDB altered outside of yum. Installing : 2:ncat-7.60-1.x86_64 1/1 Verifying : 2:ncat-7.60-1.x86_64 1/1 Installed: ncat.x86_64 2:7.60-1 Complete!
Example 9: List all installed packages
In one of our earlier examples, we used the yum list command to check if a package was installed.
We could use the yum list command to in fact list all packages presently installed on the system using the command yum list installed.
[root@linuxnix ~]# yum list installed 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 Installed Packages ConsoleKit.x86_64 0.4.1-6.el6 @anaconda-CentOS-201605220104.x86_64/6.8 ConsoleKit-libs.x86_64 0.4.1-6.el6 @anaconda-CentOS-201605220104.x86_64/6.8 ConsoleKit-x11.x86_64 0.4.1-6.el6 @anaconda-CentOS-201605220104.x86_64/6.8 DeviceKit-power.x86_64 014-3.el6 @anaconda-CentOS-201605220104.x86_64/6.8 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 MAKEDEV.x86_64 3.24-6.el6 @anaconda-CentOS-201605220104.x86_64/6.8 ModemManager.x86_64 0.4.0-5.git20100628.el6 @anaconda-CentOS-201605220104.x86_64/6.8 MySQL-python.x86_64 1.2.3-0.3.c1.1.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 -----------------------------------------------------------------------------------------------------------------------output truncated for brevity
When you run the yum list installed command you may notice that some of the packages are listed in bold.
The bold text implies that the installed version of the package is older than the latest version of the package available in the repository.
Example 10: List all available and installed packages
To list every package that is available to be installed via yum, use the yum list all command:
[root@linuxnix ~]# yum list all | more 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 Installed Packages ConsoleKit.x86_64 0.4.1-6.el6 @anaconda-CentOS-201605220104.x86_64/6.8 ConsoleKit-libs.x86_64 0.4.1-6.el6 @anaconda-CentOS-201605220104.x86_64/6.8 ConsoleKit-x11.x86_64 0.4.1-6.el6 @anaconda-CentOS-201605220104.x86_64/6.8 DeviceKit-power.x86_64 014-3.el6 @anaconda-CentOS-201605220104.x86_64/6.8 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 MAKEDEV.x86_64 3.24-6.el6 @anaconda-CentOS-201605220104.x86_64/6.8 ModemManager.x86_64 0.4.0-5.git20100628.el6 @anaconda-CentOS-201605220104.x86_64/6.8 MySQL-python.x86_64 1.2.3-0.3.c1.1.el6 @anaconda-CentOS-201605220104.x86_64/6.8 NetworkManager.x86_64 1:0.8.1-107.el6 @anaconda-CentOS-201605220104.x86_64/6.8 ----------------------------------------------------------output truncated for brevity
The list could comprise of thousands of packages depending on the repositories that have added on the system.
The yum list all command will list all the installed packages first followed by a listing of the available packages from repositories in an alphabetical order.
Example 11: Check for updates available for packages
To find how many of installed packages on your system have updates available, to check use the following command.
[root@linuxnix ~]# yum check-update 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 GConf2.x86_64 2.28.0-7.el6 base GConf2-gtk.x86_64 2.28.0-7.el6 base NetworkManager.x86_64 1:0.8.1-113.el6 base NetworkManager-glib.x86_64 1:0.8.1-113.el6 base NetworkManager-gnome.x86_64 1:0.8.1-113.el6 base ORBit2.x86_64 2.14.17-6.el6_8 base abrt.x86_64 2.0.8-43.el6.centos base abrt-addon-ccpp.x86_64 2.0.8-43.el6.centos base abrt-addon-kerneloops.x86_64 2.0.8-43.el6.centos base abrt-addon-python.x86_64 2.0.8-43.el6.centos base abrt-cli.x86_64 2.0.8-43.el6.centos base abrt-desktop.x86_64 2.0.8-43.el6.centos base abrt-gui.x86_64 2.0.8-43.el6.centos base abrt-libs.x86_64 2.0.8-43.el6.centos base abrt-python.x86_64 2.0.8-43.el6.centos base abrt-tui.x86_64 2.0.8-43.el6.centos base acl.x86_64 2.2.49-7.el6_9.1 updates alsa-utils.x86_64 1.1.0-10.el6 base -----------------------------------output truncated for brevity
Example 12: Update all packages for which updates are available
To update our system with the latest packages and security patches available from the repositories, use the yum update command.
[root@linuxnix ~]# yum update Loaded plugins: fastestmirror, refresh-packagekit, security Setting up Update Process 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 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 ---> Package NetworkManager.x86_64 1:0.8.1-107.el6 will be updated ---> Package NetworkManager.x86_64 1:0.8.1-113.el6 will be an update ---> Package NetworkManager-glib.x86_64 1:0.8.1-107.el6 will be updated ---> Package NetworkManager-glib.x86_64 1:0.8.1-113.el6 will be an update ---> Package NetworkManager-gnome.x86_64 1:0.8.1-107.el6 will be updated -----------------------------------------------------output truncated for brevity
Example 13: Look for security updates only
In case you are interested in security updates only, you could use the –security option with the check-update and update commands as shown below:
[root@linuxnix ~]# yum --security check-update 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 Limiting package lists to security relevant ones No packages needed for security; 436 packages available [root@linuxnix ~]#
Example 14: Install security updates only.
To install only security updates on the system use the following command:
[root@linuxnix ~]# yum --security update Loaded plugins: fastestmirror, refresh-packagekit, security Setting up Update Process Loading mirror speeds from cached hostfile * base: centos.mirror.snu.edu.in * epel: repo.ugm.ac.id * extras: centos.mirror.snu.edu.in * updates: centos.mirror.snu.edu.in Resolving Dependencies Limiting packages to security relevant ones No packages needed for security; 436 packages available [root@linuxnix ~]#
In order for this functionality to work, the yum-plugin-security yum plugin must be installed on the target system.
Conclusion
In this article, we’ve covered the basics of yum and many of the common examples. In the next article, we’ll cover more usage examples and a few tips and tricks.
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