32 YUM Command Examples – To Manage Linux Packages (Part1)
Yum is an acronym for yellow dog updater modified. The yum package manager is an earlier implementation of yep, the package manager used by yellow dog Linux. The yum package manager can be regarded as a front end for the rpm package manager with more advanced features like the ability to search for packages in online and remote repositories and most importantly the ability to resolve package dependencies. After Fedora 22 onwards, yum was switched in favor of dnf as the default package manager. To access the yum command line interface we use the yum command examples.
In this article, we will share some of the most useful and frequently used options with the yum command. We’ll be using a centos 7 system for all the examples in this article.
Example1: Search for a package – yum command examples
How you 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 screen package
[root@sahil-centos7 ~]# yum search screen | grep -E '^screen' screen.x86_64 : A screen manager that supports multiple logins on one terminal screengrab.x86_64 : Screen grabber
The yum search command will search for the search term in the package name and description. Therefore, the above yum search command had returned several results as many packages seemed to have the word screen mentioned in their description somewhere. So, I filtered the output through grep.
Example2: Find out which package provides a file
In order to check which package provides a particular file or executable, we use the yum provides the command with the file name to find out the name of the package which provides that file.
Demonstrate let’s search which package provides the yum command itself.
[root@sahil-centos7 ~]# yum provides yum Loaded plugins: fastestmirror, langpacks Loading mirror speeds from cached hostfile * base: ftp.iitm.ac.in * epel: mirror1.ku.ac.th * extras: ftp.iitm.ac.in * updates: ftp.iitm.ac.in yum-3.4.3-154.el7.centos.noarch : RPM package installer/updater/manager Repo : base yum-3.4.3-150.el7.centos.noarch : RPM package installer/updater/manager Repo : @anaconda
Example3: Install a package
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.
So, to install the screen package on our system we would use the following yum command examples
yum install screen
Example4: Download a package without installing it
To download a package locally without installing it, we use the –downloadonly option with the yum command and we could optionally use the –downloaddir option as well to specify the directory in which we want the downloaded package to be placed in.
Download the screen package to the /tmp directory without installing it, we could type the following:
[root@sahil-centos7 ~]# yum install --downloadonly --downloaddir=/tmp screen
The above command indeed downloads the package to the /tmp directory. We verify the same as follows
[root@sahil-centos7 ~]# ls -l /tmp/screen-4.1.0-0.23.20120314git3c2946.el7_2.x86_64.rpm -rw-r--r--. 1 root root 565052 Feb 17 2016 /tmp/screen-4.1.0-0.23.20120314git3c2946.el7_2.x86_64.rpm
Example5: Uninstall/Remove a package
Uninstall/Remove a package we use the yum remove command followed by the package name.
For example, to uninstall the screen package, we would type the following
yum remove screen
Example6: Assume yes for actions
Until now while installing or removing packages, you might have noticed that yum prompts you for confirmation if you would like to proceed with the action.
If you wish to skip this check then you can add the -y option with the yum command you are executing to confirm yes to yum to avoid getting prompted.
Install the screen package without being prompted for confirmation, you would type the following command:
yum install screen -y
Example7: Query information about a package
Obtain information about a package, we use the yum info command followed by the package name.
[root@sahil-centos7 ~]# yum info screen
Example8: Check dependencies for a package
Check for dependencies of a package using yum deplist command. For example, to take a look at the dependencies for the screen package, we would type:
yum deplist screen
Example9: Check if a package is installed
We use the yum list command followed by the package to check if it’s installed on the system. Let’s demonstrate by checking for the pcre (Perl compatible regular expressions) package.
[root@sahil-centos7 ~]# yum list pcre Available Packages pcre.i686 8.32-17.el7 base pcre.x86_64 8.32-17.el7 base
From the above output, we can validate that a version of the package is installed on the system and an update for the package is also available.
Example10: Install a locally downloaded package
You can use the yum localinstall command to install any locally downloaded packages. Here yum will use a downloaded .rpm package file to install the package and will search for any dependencies for the package in online repositories and download and install them. To install the screen package that we had downloaded in a previous example in this manner, we could type the following command
yum localinstall screen -y
Example11: list all installed packages
To list all packages currently installed on the system, use below command
yum list installed
The output of the yum list installed command will include packages that were installed directly using the rpm command and not yum.
Example12: List all available and installed packages
List all packages currently installed on the system as well as those available for install
yum list all
Example13: Check for updates available for packages
To list installed packages having updates available use the following yum command examples
Example14: Update system
Update our system with the latest packages and security patches available from the repositories including the kernel if an update is available
Example15: Update a single package
To update a package using yum, we use the yum update command followed by the package name.
For example, to update the pcre package we listed in an earlier example, we would use yum command examples below
yum update pcre
Example16: List enabled repositories
Repositories are huge collections of packages that have been made available for download and installation.
Linux distributions come with some official repository addresses which you may use to download packages from.
In addition to online yum repositories, we can create our own local yum repositories to install packages on the same server on which the repository resides.
To list yum repositories enabled on your system from which you can download and install packages from, use the yum repolist command
[root@sahil-centos7 ~]# yum repolist base/7/x86_64 CentOS-7 - Base 9,591 epel/x86_64 Extra Packages for Enterprise Linux 7 - x86_64 12,156 extras/7/x86_64 CentOS-7 - Extras 327 puppetlabs-pc1/x86_64 Puppet Labs PC1 Repository el 7 - x86_64 132 updates/7/x86_64 CentOS-7 - Updates 1,573 repolist: 23,779
This concludes our first part of this article 32 yum command examples, where we are covering yum in depth. In the next part, we will cover more yum features like working with groups of packages and excluding certain packages from being updated.
Thanks for your wonderful Support and Encouragement
Stay Connected With Us. Learn More and Earn More