Yum is a must-use for any Red Hat, CentOS, or Fedora system administrator. It will search for packages for you, install them, update them, and even remove them. It will automatically resolve and process dependencies. It will detect package conflicts and and abort package installation. Typically, there isn’t even a reason to reboot your server when using yum. Yum has lots of options. Hopefully, I can list most of them in this article for you.
Install Packages with Yum
If you machine is missing a package that you need, you can install it using the “yum install” command.
Example: We need the “wget” command on our system, we will install it using “yum install”.
# yum install wget Loaded plugins: fastestmirror, refresh-packagekit Loading mirror speeds from cached hostfile * base: mirror.stanford.edu * epel: mirrors.kernel.org * extras: mirror.san.fastserv.com * updates: yum.phx.singlehop.com Setting up Install Process Resolving Dependencies There are unfinished transactions remaining. You might consider running yum-complete-transaction first to finish them. --> Running transaction check ---> Package wget.x86_64 0:1.12-1.8.el6 will be updated ---> Package wget.x86_64 0:1.12-1.11.el6_5 will be an update --> Finished Dependency Resolution Dependencies Resolved ============================================================================================================= Package Arch Version Repository Size ============================================================================================================= Updating: wget x86_64 1.12-1.11.el6_5 updates 483 k Transaction Summary ============================================================================================================= Upgrade 1 Package(s) Total download size: 483 k Is this ok [y/N]: y Downloading Packages: wget-1.12-1.11.el6_5.x86_64.rpm | 483 kB 00:00 Running rpm_check_debug Running Transaction Test Transaction Test Succeeded Running Transaction Updating : wget-1.12-1.11.el6_5.x86_64 1/2 Cleanup : wget-1.12-1.8.el6.x86_64 2/2 Verifying : wget-1.12-1.11.el6_5.x86_64 1/2 Verifying : wget-1.12-1.8.el6.x86_64 2/2 Updated: wget.x86_64 0:1.12-1.11.el6_5 Complete!
You can install more than one package with one command by specifying them one after another.
# yum install <package1> <package2> <package3> <package4>
List and Install a Package Group
There are packages that work together and typically are installed at the same time. They are typically grouped together in a “package group”. You can list all of the available package groups using:
# yum grouplist <hidden>
The hidden option will include the typically hidden package groups in the list.
Installing a package group is as simple as using the yum groupinstall <package group name> as shown below:
# yum groupinstall "SNMP Support"
Get More Information on a Package
If you want to get more information on a specific package, you can get more by using “yum info”.
# yum info wget ... Installed Packages Name : wget Arch : x86_64 Version : 1.12 Release : 1.11.el6_5 Size : 1.8 M Repo : installed From repo : updates Summary : A utility for retrieving files using the HTTP or FTP protocols URL : http://www.gnu.org/software/wget/ License : GPLv3+ and GFDL Description : GNU Wget is a file retrieval utility which can use either the HTTP or : FTP protocols. Wget features include the ability to work in the : background while you are logged out, recursive retrieval of : directories, file name wildcard matching, remote file timestamp : storage and comparison, use of Rest with FTP servers and Range with : HTTP servers to retrieve files over slow or unstable connections, : support for Proxy servers, and configurability.
Remove Packages with Yum
Just like installing packages is done with yum, you can delete them using “yum remove”
# yum remove wget
List all packages installed on your system
# yum list installed
Update Your Complete System with Yum
You can use yum to check to see if there are any updates for your system. The check-update option will search each package for updates.
Example: Using Yum to see if there are any updates for your system.
# yum check-update
or you could check to see if there are any updates related to a specific package already installed on your system.
Example: Below I check to see if there are any updates for openssh for my system
# yum check-update | grep openssh openssh.x86_64 5.3p1-94.el6 base openssh-askpass.x86_64 5.3p1-94.el6 base openssh-clients.x86_64 5.3p1-94.el6 base openssh-server.x86_64 5.3p1-94.el6 base
Update Packages with Yum
Now that we know there are updates for our openssh package, we want to apply the updates. We do this using the “yum update” command.
Example: Now use yum to update the openssh packages on your system. By using the “-y” option, you are responding to the question you would otherwise be asked: “Is this ok [y/N]:”
# yum -y update openssh.x86_64 Loaded plugins: fastestmirror, refresh-packagekit Loading mirror speeds from cached hostfile * base: mirror.raystedman.net * epel: mirrors.kernel.org * extras: mirror.san.fastserv.com * updates: yum.phx.singlehop.com .... Updated: openssh.x86_64 0:5.3p1-94.el6 Dependency Updated: openssh-askpass.x86_64 0:5.3p1-94.el6 openssh-clients.x86_64 0:5.3p1-94.el6 openssh-server.x86_64 0:5.3p1-94.el6 Complete!
Finding Which Package Contains a Particular File
Frequently, I know what command I am looking for, but am not certain on the exact name of the package that will install it. In cases like this, you can use the “provides” or “whatprovides” option to yum.
Normally, you would think that you could just type the file that you are searching for, but that’s not quite the case.
Example: Below I attempt to find out what package would provide me with the “psql” command, but I get this strange message instead.
# yum provides psql Loaded plugins: fastestmirror, refresh-packagekit Loading mirror speeds from cached hostfile * base: mirror.raystedman.net * epel: mirrors.kernel.org * extras: mirror.san.fastserv.com * updates: yum.phx.singlehop.com Warning: 3.0.x versions of yum would erroneously match against filenames. You can use "*/psql" and/or "*bin/psql" to get that behaviour
What this is trying to say to us is that we need to either specify the path and filename of the file we are searching for, or we can use wildcards for part of it.
Example: Below, I search for the “psql” file again, but this time use the “*” to specify the path. This time with success!
# yum provides */psql Loaded plugins: fastestmirror, refresh-packagekit Loading mirror speeds from cached hostfile * base: mirror.raystedman.net * epel: mirrors.kernel.org * extras: mirror.san.fastserv.com * updates: yum.phx.singlehop.com base/filelists_db | 5.9 MB 00:00 epel/filelists_db | 8.6 MB 00:00 extras/filelists_db | 11 kB 00:00 nginx/filelists_db | 13 kB 00:00 updates/filelists_db | 1.9 MB 00:00 varnish-3.0/filelists | 13 kB 00:00 postgresql-8.4.18-1.el6_4.i686 : PostgreSQL client programs Repo : base Matched from: Filename : /usr/bin/psql
Clean the Yum Cache
Yum will create a cache which includes metadata and packages that it has used and discovered as you have used yum. This cache is stored in /var/cache/yum. In this directory, you will find a directory for your server’s architecture (in my case x86_64) which in turn contains a version directory and then a folder for each repository it has used. Incidentally, you can configure whether a repository is cached or not by editing the “keepcache” parameter to either 0 or 1. From time to time, these cache files will get a bit messed up and the yum cache will need to be “cleaned.”
Strangely enough, you can clean the cache by using the yum command. You can specify what part of the yum cache to clean up by using one of these keywords:
yum clean headers | packages | metadata | dbcache | plugins | expire-cache | rpmdb | all
Example: Below we use yum to clean the metadata from the yum cache
# yum clean metadata Loaded plugins: fastestmirror, refresh-packagekit Cleaning repos: base epel extras nginx updates varnish-3.0 22 metadata files removed 14 sqlite files removed 0 metadata files removed
Example: Below, we use the “all” option to clear the entire yum cache.
# yum clean all Loaded plugins: fastestmirror, refresh-packagekit Cleaning repos: base epel extras nginx updates varnish-3.0 Cleaning up Everything Cleaning up list of fastest mirrors
Example: Now, we want to rebuild the yum cache. To do this, we use yum makecache.
# yum makecache Loaded plugins: fastestmirror, refresh-packagekit Determining fastest mirrors epel/metalink | 11 kB 00:00 * base: mirror.stanford.edu * epel: mirrors.kernel.org * extras: mirror.san.fastserv.com * updates: yum.phx.singlehop.com base | 3.7 kB 00:00 base/group_gz | 220 kB 00:00 base/filelists_db | 5.9 MB 00:00 base/primary_db | 4.4 MB 00:00 base/other_db | 2.8 MB 00:00 epel | 4.4 kB 00:00 epel/group_gz | 237 kB 00:00 epel/filelists_db | 8.6 MB 00:00 epel/primary_db | 6.2 MB 00:00 epel/other_db | 3.6 MB 00:00 epel/updateinfo | 805 kB 00:00 extras | 3.4 kB 00:00 extras/filelists_db | 11 kB 00:00 extras/prestodelta | 907 B 00:00 extras/primary_db | 19 kB 00:00 extras/other_db | 5.8 kB 00:00 nginx | 2.9 kB 00:00 nginx/filelists_db | 13 kB 00:00 nginx/primary_db | 29 kB 00:00 nginx/other_db | 12 kB 00:00 updates | 3.4 kB 00:00 updates/filelists_db | 1.9 MB 00:00 updates/prestodelta | 297 kB 00:00 updates/primary_db | 3.2 MB 00:00 updates/other_db | 26 MB 00:01 varnish-3.0 | 951 B 00:00 varnish-3.0/filelists | 13 kB 00:00 varnish-3.0/primary | 7.0 kB 00:00 varnish-3.0/other | 8.5 kB 00:00 varnish-3.0 26/26 varnish-3.0 26/26 varnish-3.0 26/26 epel/pkgtags | 1.0 MB 00:00 Metadata Cache Created
and like that, our yum cache has been recreated.
Automate Your System Updates with Yum-Cron
If you just want your system to update itself automatically on a scheduled basis. You can configure this using “Yum-Cron”. Yum-Cron will not reboot your system after updates, but it has to be installed before it can be used. Here are the quick steps to installing Yum-Cron:
Install Yum-cron with Yum
# yum install yum-cron
Configure Yum-cron to Startup at Boot
# chkconfig yum-cron on
If you have the pre-installed updater service on your machine, you can turn it off by default: “chkconfig yum-updatesd off; service yum-updatesd stop”.
Configure the Yum-cron Service
The yum-cron options are stored in the /etc/sysconfig/yum-cron configuration file. You should review the options configured in this file. At a minimum, you will want to configure yum-cron to send you any error messages it encounters to your email address. To do this, set these options:
ERROR_LEVEL=1 MAILTO=<your email address here>
then startup your yum-cron service
# service yum-cron start
You will find the cron file for yum-cron in /etc/cron.daily. This specifies which times and dates it yum-cron will run.
Additional Resources on Yum
Undoubtedly, I have forgotten some detail that you may need in working with yum. Luckily, there are many, many resources out there. Here is a short list: