32 Yum Command Examples Part 2 – Very Useful

In our previous part of this article, we covered the basic and most common uses of the yum package management tool like installing and removing software. In this article, we will continue our coverage of yum to include more of its interesting uses. 32 yum command examples – part2

Example17: Clear Cache Yum Command

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

yum clean all

Example18: Rebuild 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 following command.

yum makecache

Example19: Execute yum commands in quite mode

Installing packages using yum can generate a lot of output on the terminal if we are installing multiple packages with complex dependency trees. If we are not interested in viewing this output then we could use the -q option to run the yum commands in quite mode without any output on the screen. For example, to install the screen package using yum with quite mode, we could type the following command:

yum install screen -q -y

Example20: Enable verbose output

We can use the -v option with a yum command to enable more verbose output for the operation being performed.
To install the screen package using yum with verbose mode, we could type the following command:

yum install screen -v -y

Example21: Downgrade a package

To downgrade a package, we use the yum downgrade command followed by the package name.
For example, to downgrade the screen package to a lower version than the installed version we would type the following command:

yum downgrade screen

Example22: List packages not installed from a yum repository

To list packages that were not installed using a yum repository, we use the following command:

yum list extras

Example23: Using the yum interactive shell

Executing the yum shell command launches an interactive command line interface to the yum package manager.
When running things like install or remove, Yum will not complete the transaction immediately. You need to issue the run command to tell Yum to do it.  This gives you the advantage of being able to tell Yum to do several things, and then actually run the transactions. In the below example, we first perform a yum list screen to view the available packages followed by installation of the screen package.

[root@sahil-centos7 ~]# echo -e "list screen\n install screen\n run\n quit" | yum shell -y

Example24: List available package groups

YUM package groups contain packages that are often installed together to provide some particular functionality.
When we install a package group, yum will go ahead and install all the packages which belong to that group.
To list the available package groups that could be installed or have been installed already, we use the yum grouplist command.

[root@sahil-centos7 ~]# yum grouplist

Available Environment Groups:
Minimal Install
Compute Node
Infrastructure Server
File and Print Server
Cinnamon Desktop
MATE Desktop
Basic Web Server
Virtualization Host
Server with GUI
GNOME Desktop
KDE Plasma Workspaces
Development and Creative Workstation
Available Groups:
CIFS file server
Compatibility Libraries
Console Internet Tools
Development Tools
Educational Software
Electronic Lab
FCoE Storage Client
Fedora Packager
General Purpose Desktop
Graphical Administration Tools
Legacy UNIX Compatibility
Messaging Client Support
Messaging Server Support
MySQL Database client
MySQL Database server
NFS file server
Network Storage Server
SNMP Support
Scientific Support
Security Tools
Server Platform
Server Platform Development
Smart Card Support
Storage Availability Tools
System Administration Tools
System Management
TeX support
TurboGears application framework
Web-Based Enterprise Management
iSCSI Storage Client

Example25: Install a package group

In our earlier example, we saw how we might list available package groups.
to install a package group we use the yum groupinstall command followed by the group name in quotes.
For example, to install the basic web server group, execute the following command:

yum groupinstall 'Basic Web Server'

Example26: List available packages in a package group

To view packages that are part of a given package group, we use the yum groupinfo command followed by the group name in quotes.
Let’s demonstrate by checking packages part of the web server package group.

[root@sahil-centos7 ~]# yum groupinfo 'Web Server'
Loaded plugins: fastestmirror, langpacks
There is no installed groups file.
Maybe run: yum groups mark convert (see man yum)
Loading mirror speeds from cached hostfile
* base: ftp.iitm.ac.in
* epel: repo.fedoralinux.ir
* extras: ftp.iitm.ac.in
* updates: ftp.iitm.ac.in
Group: Web Server
Group-Id: web-server
Description: Allows the system to act as a web server, and run Perl and Python web applications.
Mandatory Packages:
Default Packages:
Optional Packages:

Example27: Remove a package group

To remove all packages in a package group we use the yum groupremove command followed by the package group name.
For example, to remove the web server package group we would type the following command:

yum groupremove 'Web Server'

Example28: Exclude a single package from being updated

To exclude a single package from being updated we use the -x option.
In order to exclude the kernel package from being updated while we update our system, we would type the following command:

yum update -x kernel

Example29: Exclude multiple packages from being updated

We can use the –exclude option with the yum command to exclude multiple packages from being updated by separating them by commas.
For example, to exclude all kernel and python packages from the system update we would type the following command:

yum update --exclude=kernel*,python*

Example30: View history of yum transactions

Yum treats every package management task we perform as a transaction and stores information about the most recent transactions. To view this information, we use the yum history command as shown below:

[root@sahil-centos7 ~]# yum history
Loaded plugins: fastestmirror, langpacks
ID | Login user | Date and time | Action(s) | Altered
3 | root <root> | 2017-05-15 16:46 | Install | 16 >
2 | root <root> | 2017-05-15 15:39 | Install | 1
1 | System <unset> | 2017-05-15 14:54 | Install | 625
history list

Example31: Get details about a transaction

To obtain information about one of the transactions listed in the yum history output, we use the yum history info command followed by the transaction id. To demonstrate let’s check out the details of our most recent transaction with id 18.

[root@sahil-centos7 ~]# yum history info 18
Loaded plugins: fastestmirror, langpacks
Transaction ID : 18
Begin time : Mon Dec 25 22:01:15 2017
Begin rpmdb : 754:0834155f2e3a454d31d7b3200ba06741288d700a
End time : 22:01:16 2017 (1 seconds)
End rpmdb : 755:ce0e70589c3c3d4ff3c2f1ec71c37e4b827f3f9a
User : root <root>
Return-Code : Success
Command Line : shell -y
Additional non-default information stored: 1
Transaction performed with:
Installed rpm-4.11.3-21.el7.x86_64 @anaconda
Installed yum-3.4.3-150.el7.centos.noarch @anaconda
Installed yum-plugin-fastestmirror-1.1.31-40.el7.noarch @anaconda
Packages Altered:
Install screen-4.1.0-0.23.20120314git3c2946.el7_2.x86_64 @base
history info

Example32: Rollback a transaction yum command

This feature is very helpful for cases when we’ve accidentally performed a yum operation which we need to reverse. Yum allows us to rollback transactions. For example, to roll back the most recent transaction on the system, i.e. the transaction with id 18, we would execute the following command:

[root@sahil-centos7 ~]# yum history undo 18

Installed size: 914 k
Is this ok [y/N]: y

Erasing : screen-4.1.0-0.23.20120314git3c2946.el7_2.x86_64 1/1
Verifying : screen-4.1.0-0.23.20120314git3c2946.el7_2.x86_64 1/1

screen.x86_64 0:4.1.0-0.23.20120314git3c2946.el7_2



This concludes our exhaustive coverage of the yum package management tool where we showed you how to install and remove packages, query and list packages, and update and downgrade packages. 32 Yum command examples Part-2

Related Articles

racadm script to reset Multiple idrac

How to Install Apache Open Office 4

chmod command


Thanks for your wonderful Support and Encouragement

Sahil Suri

I am a system administrator who loves to learn and share my knowledge with the community. I've been working in the IT industry since 2011.

Leave a Reply

Your email address will not be published. Required fields are marked *