
Yum (Yellowdog Updater Modified) is a utility provided in RHEL based systems to install, remove and search packages. It can do a lot more than just installing and removing and that's what I will demonstrate in this tutorial.
Yum installs the package dependencies automatically, for example, yum install httpd
will install the apache webserver server and it's required dependencies automatically. Something that is not that easy while installing through rpm command. With rpm you have to download all the required dependencies and then install accordingly.
The yum utility fetches the package information from a hosted repository (usually by the OS vendor). A repository is basically a collection of rpm's that are supposed to work on a particular architecture. For example, there would be a separate repository for 32 and 64 bit systems, and the same goes with RHEL 5, 6, or 7 or 8. You can host your local repository and configure yum to search, install packages from the local repository.
In the following examples, I will show you some most commonly used yum commands.
1) Search a package from the repository
The following command search entire repository for specific package:
# yum search httpd
Loaded plugins: amazon-id, rhui-lb, security
=============================================== N/S Matched: httpd ==========
httpd.x86_64 : Apache HTTP Server
httpd-devel.i686 : Development interfaces for the Apache HTTP server
httpd-devel.x86_64 : Development interfaces for the Apache HTTP server
httpd-manual.noarch : Documentation for the Apache HTTP server
httpd-tools.x86_64 : Tools for use with the Apache HTTP Server
mod_dav_svn.x86_64 : Apache httpd module for Subversion server
mod_dnssd.x86_64 : An Apache HTTPD module which adds Zeroconf support
For a more detailed output use the following command:
# yum provides httpd
Loaded plugins: amazon-id, rhui-lb, security
httpd-2.2.15-26.el6.x86_64 : Apache HTTP Server
Repo : rhui-REGION-rhel-server-releases
Matched from:
yum provides */httpd
Searches in yum packages to find the package that contains 'httpd'.
It's also possible to find more information about the packages using the following command:
# yum info httpd
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
...
Installed Packages
Name : httpd
Arch : x86_64
Version : 2.2.15
Release : 69.el6.centos
Size : 3.0 M
Repo : installed
From repo : base
Summary : Apache HTTP Server
URL : http://httpd.apache.org/
License : ASL 2.0
Description : The Apache HTTP Server is a powerful, efficient, and extensible
2) Operate on Package Groups
You can list all the package groups that are installed and available on your computer. The following command will show you the installed and available package group.
# yum grouplist
...
Installed Groups:
E-mail server
Perl Support
Scalable Filesystems
Security Tools
...
Available Groups:
Additional Development
Backup Client
Backup Server
Base
CIFS file server
.....
If you want to have a brief idea about the packages included in a group, you can use the command the parameter groupinfo
.
# yum groupinfo "PHP Support"
Loaded plugins: fastestmirror
Setting up Group Process
...
Group: PHP Support
Description: PHP web application framework.
Mandatory Packages:
php
Default Packages:
php-gd
php-pdo
php-pear
php-xml
Optional Packages:
php-ldap
php-mysql
...
You can install an individual package group with the group install option. For example, we will install the package group PHP Support. This package group contains the required php packages.
# yum groupinstall "PHP Support"
Loaded plugins: amazon-id, downloadonly, rhui-lb, security
Setting up Group Process
Warning: Group Support does not exist.
Resolving Dependencies
--> Running transaction check
---> Package php.x86_64 0:5.3.3-23.el6_4 will be installed
--> Processing Dependency: php-common(x86-64) = 5.3.3-23.el6_4 for package: php-5.3.3-23.el6_4.x86_64
--> Processing Dependency: php-cli(x86-64) = 5.3.3-23.el6_4 for package: php-5.3.3-23.el6_4.x86_64
---> Package php-gd.x86_64 0:5.3.3-23.el6_4 will be installed
--> Processing Dependency: libXpm.so.4()(64bit) for package: php-gd-5.3.3-23.el6_4.x86_64
Dependencies Resolved
=====================================================================
Package Arch Version Repository Size
=====================================================================
Installing:
php x86_64 5.3.3-23.el6_4 rhui-REGION-rhel-server-releases 1.1 M
...
You can update a group packages with the following command:
]# yum groupupdate "PHP Support"
Loaded plugins: fastestmirror
Setting up Group Process
Loading mirror speeds from cached hostfile
...
Resolving Dependencies
--> Running transaction check
---> Package php.x86_64 0:5.3.3-49.el6 will be installed
--> Processing Dependency: php-common(x86-64) = 5.3.3-49.el6 for package: php-5.3.3-49.el6.x86_64
--> Processing Dependency: php-cli(x86-64) = 5.3.3-49.el6 for package: php-5.3.3-49.el6.x86_64
...
To remove a group package, use the command following:
# yum groupremove "PHP Support"
Loaded plugins: fastestmirror
Setting up Group Process
Loading mirror speeds from cached hostfile
...
Resolving Dependencies
--> Running transaction check
---> Package php.x86_64 0:5.3.3-49.el6 will be erased
---> Package php-gd.x86_64 0:5.3.3-49.el6 will be erased
...
3) Install package using YUM
A package can be installed using yum install
command as follows:
# yum install httpd
Loaded plugins: amazon-id, rhui-lb, security
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package httpd.x86_64 0:2.2.15-29.el6_4 will be installed
--> Processing Dependency: httpd-tools = 2.2.15-29.el6_4 for package: httpd-2.2.15-29.el6_4.x86_64
--> Processing Dependency: apr-util-ldap for package: httpd-2.2.15-29.el6_4.x86_64
Dependencies Resolved
=============================================================================
Package Arch Version Repository Size
=============================================================================
Installing:
httpd x86_64 2.2.15-29.el6_4 rhui-REGION-rhel-server-releases 821
As you can see yum added additional packages with 'httpd' installation. This is called the dependency resolution is done by yum. If you want yum not to prompt for the [y/N] option. Use yum install -y httpd
4) Reinsitall a package
Some times you can face somes issues with the packages already in your system. One possibility is to uninstall and reinstall again but it's too long. You can just ask to yum to do the reinstallation for you and it will be done automatically
# yum reinstall httpd -y
This process will just reinstall the packages for you
5) Update packages
When you want to do an update, you can need to first check all the available updates. This is possible with the check-update
parameter. If there are some updates availables, you will receive an output, otherwise nothing.
# yum check-update
You can directly update all the packages on the server using the 'update' command. This will update the kernel package as well to the latest version, which means your OS will be updated to the latest provided by RHEL.
# yum update
You can update a specific package as follows:
# yum update httpd
Loaded plugins: amazon-id, rhui-lb, security
Setting up Update Process
No Packages marked for Update
You can exclude a package during the update process with the -x
parameter
# yum update -x httpd
6) Download package RPM file without installing
Use yum to download RPM package from RHN or CentOS repository without installing it. You have to install a plugin for yum first to have yum download the rpm only. The utility name is yum-downloadonly
and can be installed through yum as follow:
# yum install yum-downloadonly
Loaded plugins: amazon-id, rhui-lb, security
Setting up Install Process
Resolving Dependencies
--> Running transaction check
Dependencies Resolved
===========================================================================
Package Arch Version Repository Size
===========================================================================
Installing:
yum-plugin-downloadonly noarch 1.1.30-14.el6 rhui-REGION-rhel-server-releases 20 k
Transaction Summary
===========================================================================
Install 1 Package(s)
Now you can just download a package from the repository without installing it by using this command:
# yum install httpd-devel --downloadonly
By default, packages are downloaded to /var/cache/yum/<arch>
directory but you can download them a specified location by adding another option to yum command
# yum install httpd-devel --downloadonly --downloaddir=/opt
7) Perform a local installation of rpm files
If you have a rpm of a package but you don't have the dependencies and you do not know where to get that. you can still have yum to install that rpm and get the required dependencies from the repository. Let's install the httpd-devel-2.2.15-29.el6_4.x86_64 RPM that we just downloaded.
# yum localinstall /opt/httpd-devel-2.2.15-29.el6_4.x86_64.rpm
Loaded plugins: amazon-id, downloadonly, rhui-lb, security
Setting up Local Package Process
Examining /opt/httpd-devel-2.2.15-29.el6_4.x86_64.rpm: httpd-devel-2.2.15-29.el6_4.x86_64
Marking /opt/httpd-devel-2.2.15-29.el6_4.x86_64.rpm to be installed
Resolving Dependencies
--> Running transaction check
---> Package httpd-devel.x86_64 0:2.2.15-29.el6_4 will be installed
--> Processing Dependency: apr-devel for package: httpd-devel-2.2.15-29.el6_4.x86_64
--> Processing Dependency: apr-util-devel for package: httpd-devel-2.2.15-29.el6_4.x86_64
--> Running transaction check
...
--> Finished Dependency Resolution
Dependencies Resolved
=============================================================================
Package Arch Version Repository Size
=============================================================================
Installing:
httpd-devel x86_64 2.2.15-29.el6_4 /httpd-devel-2.2.15-29.el6_4.x86_64 526 k
Installing for dependencies:
apr-devel x86_64 1.3.9-5.el6_2 rhui-REGION-rhel-server-releases 176 k
...
Transaction Summary
=======================================================================
Install 8 Package(s)
Upgrade 2 Package(s)
Total size: 10 M
Is this ok [y/N]: y
8) Removing packages using yum
yum remove Remove a package.
# yum remove httpd
Failed to set locale, defaulting to C
Loaded plugins: amazon-id, downloadonly, rhui-lb, security
Setting up Remove Process
Resolving Dependencies
--> Running transaction check
---> Package httpd.x86_64 0:2.2.15-29.el6_4 will be erased
--> Processing Dependency: httpd-mmn = 20051115 for package: php-5.3.3-23.el6_4.x86_64
...
--> Finished Dependency Resolution
...
Removing:
httpd x86_64 2.2.15-29.el6_4 @rhui-REGION-rhel-server-releases 2.9 M
Removing for dependencies:
httpd-devel x86_64 2.2.15-29.el6_4 @/httpd-devel-2.2.15-29.el6_4.x86_64 526 k
php x86_64 5.3.3-23.el6_4 @rhui-REGION-rhel-server-releases 3.5 M
9) List all installed packages
If you want to list all the installed packages then you can use yum list installed command. This is useful in combination with grep or to check whether a specific package has been installed. This is similar to query installed packages with rpm -qa
command.
# yum list installed
Loaded plugins: amazon-id, downloadonly, rhui-lb, security
Installed Packages
ConsoleKit.x86_64 0.4.1-3.el6 @koji-override-0/$releasever
ConsoleKit-libs.x86_64 0.4.1-3.el6 @koji-override-0/$releasever
MAKEDEV.x86_64 3.24-6.el6 @koji-override-0/$releasever
PyYAML.x86_64 3.10-3.1.el6 @koji-override-0/$releasever
Red_Hat_Enterprise_Linux-Release_Notes-6-en-US.noarch
4-2.el6 @koji-override-0/$releasever
....
10) List the available repository
List the available repository from which packages are being queried, installed and updated.
# yum repolist
Loaded plugins: amazon-id, downloadonly, rhui-lb, security
repo id repo name status
rhui-REGION-client-config-server-6 Red Hat Update Infrastructure 2.0 Client Configuration Server 6 4
rhui-REGION-rhel-server-releases Red Hat Enterprise Linux Server 6 (RPMs) 10994
rhui-REGION-rhel-server-releases-optional Red Hat Enterprise Linux Server 6 Optional (RPMs) 6250
repolist: 17248
You can list the enabled and disabled repositories
# yum repolist all
You can also choose to install a package from a specific repository
# yum --enablerepo=epel install phpmyadmin
Loaded plugins: fastestmirror
Setting up Install Process
Loading mirror speeds from cached hostfile
epel/metalink | 14 kB ...
epel | 4.7 kB 00:00
epel/primary_db | 6.0 MB 00:00
Resolving Dependencies
--> Running transaction check
---> Package phpMyAdmin.noarch 0:4.0.10.20-1.el6 will be installed
--> Processing Dependency: php-mbstring for package: phpMyAdmin-4.0.10.20-1.el6.noarch
--> Processing Dependency: php-mcrypt for package: phpMyAdmin-4.0.10.20-1.el6.noarch
--> Processing Dependency: php-mysqli for package: phpMyAdmin-4.0.10.20-1.el6.noarch
...
11) Yum history
It's possible to see the history of all the actions did by the yum command on your server.
# yum history
Loaded plugins: fastestmirror
ID | Login user | Date and time | Action(s) | Altered
-------------------------------------------------------------------------------
7 | root <root> | 2019-02-20 09:57 | Reinstall | 1
6 | root <root> | 2019-02-20 09:48 | Install | 1
5 | root <root> | 2019-02-20 09:14 | Install | 22
4 | root <root> | 2019-02-20 07:56 | I, U | 103 EE
3 | root <root> | 2017-03-01 20:32 | Install | 15
2 | root <root> | 2017-03-01 20:30 | I, U | 48
1 | System <unset> | 2017-03-01 20:16 | Install | 205
history list
The result is filtered from the newest action at the top to the old one at the end of the list. It's also possible to show the detail information of one action. For example
# yum history info 5
Loaded plugins: fastestmirror
Transaction ID : 5
Begin time : Wed Feb 20 09:14:37 2019
Begin rpmdb : 222:02bf9bb9fcdb46cf7494b5b4b01b7df711c6d44d
End time : 09:14:39 2019 (2 seconds)
End rpmdb : 244:874a3a793190f9951bca4b6de4c2326da6ec5de7
User : root <root>
Return-Code : Success
Command Line : groupinstall PHP Support
....
Packages Altered:
Dep-Install apr-1.3.9-5.el6_9.1.x86_64 @base
Dep-Install apr-util-1.3.9-3.el6_0.1.x86_64 @base
Dep-Install apr-util-ldap-1.3.9-3.el6_0.1.x86_64 @base
...
And it's possible to undo an action like to revert it. For example, let's undo the previous action 5 which was the install of the package group 'PHP Support'.
# yum history undo 5
Loaded plugins: fastestmirror
Undoing transaction 5, from Wed Feb 20 09:14:37 2019
Dep-Install apr-1.3.9-5.el6_9.1.x86_64 @base
Dep-Install apr-util-1.3.9-3.el6_0.1.x86_64 @base
Dep-Install apr-util-ldap-1.3.9-3.el6_0.1.x86_64 @base
...
...
php-cli x86_64 5.3.3-49.el6 @base 6.2 M
php-common x86_64 5.3.3-49.el6 @base 2.9 M
php-gd x86_64 5.3.3-49.el6 @base 324 k
php-pdo x86_64 5.3.3-49.el6 @base 168 k
php-pear noarch 1:1.9.4-5.el6 @base 2.2 M
php-xml x86_64 5.3.3-49.el6 @base 307 k
Transaction Summary
============================================================================================================
Remove 22 Package(s)
Installed size: 27 M
Is this ok [y/N]:
And it is possible to redo the action 5 with the command.
# yum history redo 5
or to undo the action that we did before. But first, you need to check again the history
# yum history
Loaded plugins: fastestmirror
ID | Login user | Date and time | Action(s) | Altered
-------------------------------------------------------------------------------
8 | root <root> | 2019-02-20 14:15 | Erase | 22
7 | root <root> | 2019-02-20 09:57 | Reinstall | 1
6 | root <root> | 2019-02-20 09:48 | Install | 1
5 | root <root> | 2019-02-20 09:14 | Install | 22
You can see that the action of undoing is the action 8 Erase, so you can undo it with
# yum history undo 8
But if we think about that, it's easy to just redo the action 5 if you want to revert what you have done.
12) List installed and available packages
It's possible to list all the packages that are installed in your computer with the following command:
# yum list installed
But the list can be very long so you can decide to go page per page
# yum list installed | more
or to list only a few lines
# yum list installed | head -n 20
As you can only decide to sort the lines which contain the pattern name of a package that you are searching
# yum list installed | grep php
php.x86_64 5.3.3-49.el6 @base
php-cli.x86_64 5.3.3-49.el6 @base
php-common.x86_64 5.3.3-49.el6 @base
php-gd.x86_64 5.3.3-49.el6 @base
php-pdo.x86_64 5.3.3-49.el6 @base
php-pear.noarch 1:1.9.4-5.el6 @base
php-xml.x86_64 5.3.3-49.el6 @base
Besides the installed packages, there is also the possibility to list the packages that you can install, in order words the available packages for your system but this command will be very long
# yum list available
So you can filter with grep to have the lines of packages which can have the packages that you are looking
# yum list available | grep mysql
13) Install Security update
During the update of the system, it's possible for you to only choose the security updates instead of updating all the packages if you fear a modification that could occur on one of your packages.
But first, you will need to install the plugin security
# yum -y install yum-plugin-security
...
--> Running transaction check
---> Package yum-plugin-security.noarch 0:1.1.30-42.el6_10 will be installed
Then you can display all the security update
# yum updateinfo list security all
Then you can install security updates
# yum update --security
Or you can choose to upgrade all the packages which have at least security info to last security update
# yum --security update-minimal
Conclusion
Apt is used with the Debian distributions and handles deb packages whereas Yum is used in RHEL based distros including CentOS, Fedora which handles RPM software packages. Fedora now uses DNF for rpm package management.
If you have any questions or feedback, feel free to leave a comment.
Read Also:
- How to Add Repos to Yum in Linux
- Difference Between Linux Yum and Up2date Command
- Topgrade - Command Line Tool to Upgrade All Packages on Linux