Linux yum command reference (examples)

Summary: A CentOS Linux yum command cheat sheet (reference page).

I've been working with the CentOS Linux yum command a lot lately, so I thought I'd create a yum reference page with a lot of examples while it's still fresh in my mind. I've organized the yum commands below by task (i.e., list, install, update, information, remove).

Contents

Here's a list of shortcut links to the example yum commands shown on this page:

List all available yum packages

To list all packages that are available to you using the yum command, use the yum list command:

yum list all

That should be a long list, so you'll probably want to pipe that into more or grep, like this:

yum list all | more

or this:

yum list all | grep -v installed | more

List installed yum packages

To list all installed packages use the yum list installed command:

yum list installed

or

yum list installed | more

See if an individual yum package is installed

To see if a particular package is installed the yum list command is still good. On my test server this command:

yum list mysql

That example yum command yields this output:

Installed Packages
mysql.i386                  5.0.45-7.el5      installed

By adding a wildcard to the end of that command I can get a list of all "mysql*" packages that are installed:

yum list mysql*

That command yields this output:

Installed Packages
MySQL-python.i386           1.2.1-1           installed
mysql.i386                  5.0.45-7.el5      installed
mysql-bench.i386            5.0.45-7.el5      installed
mysql-connector-odbc.i386   3.51.12-2.2       installed
mysql-devel.i386            5.0.45-7.el5      installed
mysql-server.i386           5.0.45-7.el5      installed
mysql-test.i386             5.0.45-7.el5      installed

Search for a yum package

If you don't know the exact name of a package, you can search for it like this:

yum search mysql

To install a new yum package

To install a new package on a Linux system using yum, use the yum install command. For instance, to install the gcc development environment, use this command:

yum install gcc

To get rid of a particular error during a recent install I had to install the libxml2 package, and did so like this:

yum install libxml2

To update an installed yum package

To update a package that is already installed, use the yum update command:

yum update perl

I just tried this update command with Perl on my Linux system (which I knew probably needed to be updated), and here's the output from the previous command:

yum update perl
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: pubmirrors.reflected.net
 * updates: mirror.fdcservers.net
 * addons: chi-10g-1-mirror.fastsoft.net
 * extras: mirror.fdcservers.net
Setting up Update Process
Resolving Dependencies
--> Running transaction check
---> Package perl.i386 4:5.8.8-18.el5_3.1 set to be updated
--> Finished Dependency Resolution

Dependencies Resolved

=====================================================================================================================================================
 Package                        Arch                           Version                                       Repository                         Size
=====================================================================================================================================================
Updating:
 perl                           i386                           4:5.8.8-18.el5_3.1                            updates                            12 M

Transaction Summary
=====================================================================================================================================================
Install      0 Package(s)         
Update       1 Package(s)         
Remove       0 Package(s)         

Total download size: 12 M
Is this ok [y/N]: _

As you can see, the yum system prompted me before actually applying the update.

As a second example, to resolve the recent (2014) Unix/Linux Bash security vulnerability, all I had to do was run this yum update command:

yum update bash

Linux system updates

To find out which packages on your system have updates available, use this command:

yum check-update

To keep your Linux system up to date, including all of the latest patches and security updates, use this command:

yum update

Regarding this command, the yum man page states, "If run without any packages, `update` will update every currently installed package."

To remove a yum package

To remove an installed package (obviously you want to be very careful here), use the yum remove command. To remove an old version of MySQL, I used this command:

yum remove mysql

Note that other installed packages may have dependencies on the package you're removing, and if so, the yum command will prompt you to remove those other packages as well. Again, be careful when removing/deleting packages.

Information about an installed yum package

To find information about an installed package, use the yum info command. This command:

yum info mysql

yields this output on my current Linux system:

Installed Packages
Name       : mysql
Arch       : i386
Version    : 5.0.45
Release    : 7.el5
Size       : 7.3 M
Repo       : installed
Summary    : MySQL client programs and shared libraries.
URL        : http://www.mysql.com
License    : GPLv2 with exceptions
Description: MySQL is a multi-user, multi-threaded SQL database server. MySQL is a client/server implementation consisting of a server daemon
           : (mysqld) and many different client programs and libraries. The base package contains the MySQL client programs, the client shared
           : libraries, and generic MySQL files.

Checking your yum history

Use this command to list the history of most yum commands that have been run on your system:

yum history

I just ran that command, and it doesn't seem to show informational commands that have been run, but it does show commands that have affected the system, such as packages that were installed, updated, or removed.

Relating files to yum packages

Another really cool yum command option is that you can use the whatprovides option to go from a file on your Linux system to the package that provides that file. For instance, this command:

yum whatprovides /etc/my.cnf

yields this output:

mysql-5.0.45-7.el5.i386 : MySQL client programs and shared libraries.
Matched from:
Filename    : /etc/my.cnf

mysql-5.0.45-7.el5.i386 : MySQL client programs and shared libraries.
Matched from:
Other       : Provides-match: /etc/my.cnf

This tells me that the file /etc/my.cnf came from (or belongs to) the mysql-5.0.45-7.el5.i386 package. In this case I knew that this was a MySQL configuration file, but in general, this is a really nice option.

The yum command - More information

For more information, read the "man page" for the yum command on your Linux system using this command:

man yum

or visit this Linux yum man page that I've posted on our website.

Also, if you have any yum command examples you'd like to share, feel free to add them in the comments section below.