Open Source

Getting started with the yum package manager

Vincent Danen introduces you to the yum package manager, including basic configuration and some common commands.

There are a variety of package managers available for different Linux distributions. Mandriva uses urpmi; Debian and Ubuntu use apt. Fedora and Red Hat use yum, while Gentoo uses portage. Some distributions provide support for more than one package manager as well.

This week, we take a look at yum, or Yellowdog Updater Modified. Yum is written in python and has been in use with Fedora and Red Hat for many years. Yum has been proven to work, and despite some criticism as to its speed in comparison to other package mangers, it does the job, even if it is a little bit slower.

The main yum configuration file is /etc/yum.conf and per-repository configuration files live in the /etc/yum.repos.d/ directory. These files, as installed, are largely sufficient as the Red Hat/Fedora installer takes care of adding update sources. Unless you plan on adding other repositories or have a need to tweak certain configuration settings, these configuration files work as-is. If you would like to figure out the various options and tweak the configuration file, the yum.conf(5) manpage will help you there.

Yum itself is quite straightforward. Most individuals will likely use graphical frontends to yum, but knowing the yum commands directly is a great idea in case X is not working or you are working remotely on a server.

To install a package with yum, use the install command:

# yum install zsh

This will install the zsh package and any dependencies it may have. You can specify more than one package at a time to install (i.e., yum install zsh joe).

If you are not sure what a package is called, you can search the repository metadata using yum's search command. For instance, if you are working with some python code and need the MySQL interface available, but don't have it installed and really don't know what it is called, search for it:

# yum search MySQL | grep python

With this command, you are searching for any package related to MySQL, and then filtering that list for those packages that contain the word python. The first hit on that search is MySQL-python, which would be the package you are looking for.

If you want to list an available package, you can use the list command. This will list all available packages and note which are installed. This is useful particularly if you are using a 64-bit distribution and may require a 32-bit package. For instance:

# yum list openssl
Loaded plugins: refresh-packagekit
Installed Packages
openssl.x86_64                                                        0.9.8g-12.fc10                                                         installed
Available Packages
openssl.i386                                                          0.9.8g-12.fc10                                                         updates
openssl.i686                                                          0.9.8g-12.fc10                                                         updates

To upgrade packages, either specify the package to upgrade with the update command or do not specify any packages to upgrade everything that has an updated package available:

# yum update

And finally, a few other quick commands. To remove a package from the system, use the remove command. This will remove the noted package as well as any requirements for that package that are no longer required by other packages. To get full information on a package, such as version, architecture, and a description, use yum info [package]. To find out if any package needs to be upgraded, but without performing any upgrade actions, use yum check-update and a list of available updates will be printed.

Overall, yum is a decent package manager. It doesn't feel as fast as urpmi, but it does feel more polished. If you are used to other package managers, it may take some time to remember the commands, but the manpage that accompanies it is very well written and easy to understand.

Get the PDF version of this tip here.

Delivered each Tuesday, TechRepublic's free Linux and Open Source newsletter provides tips, articles, and other resources to help you hone your Linux skills. Automatically sign up today!

About

Vincent Danen works on the Red Hat Security Response Team and lives in Canada. He has been writing about and developing on Linux for over 10 years and is a veteran Mac user.

9 comments
lsatenstein
lsatenstein

You should introduce yumex, which for the most part,is a graphical yum I stopped using yum a long time ago. Yumex allows me to quickly do the things that take multiple commands with yum.

weiy
weiy

How to use yum to update some old versions of Fedora, like Fedora 8 or Fedora 7?

rgermanbp
rgermanbp

How to troubleshoot yum behind proxy?

chewjaco
chewjaco

Very informative post thank you. There is a GUI form of YUM called Yum extender for those that wish to use a point and click version instead of command line. It provides descriptive information about packages and also provides debugging information on errors.

hdaneker
hdaneker

A way to make your own repository would be helpful!! I have not been able to get this to work correctly.

Photogenic Memory
Photogenic Memory

There is a draw back but I'm unsure if it's from lack of experience. How can you fall back to an older application with yum? Fir instance; what happens if you install an app and it's doesn't work like you want it to? How do you roll back? Also when you do yum update; you can't pick and choose which libs you want install? It updated everything in batch. Overall, I like this package manager. It's served me well.

kmilind
kmilind

try yummex. it lets you set proxy from one of its options / preferences.

garnerl
garnerl

1. Install createrepo 2. Make a directory for your RPMS, something like "mkdir -p /var/htdocs/repo/RPMS" and put your RPMS in it. 3. Run createrepo against the directory above your RPMS: "createrepo /var/htdocs/repo". You should now have a new directory "/ave/htdocs/repo/repodata". If step 3 worked, you can create a config file in /etc/yum.repos.d and start using it: [myrepo] name=My Repository baseurl=http://myhost/repo gpgcheck=0 enabled=1 This assumes that your DocumentRoot is "/var/htdocs"; adjust as needed. You might want to consider things like different architectures and software types when setting up your repo directory structure.

adunstan
adunstan

I don't know how to roll back an update, but to only update certain packages, list those packages (wildcards allowed): yum update libwhatever yum update 'kde*' yum update 'a*' 'b*' Remember to use quotes to keep the shell from expanding your wildcards.

Editor's Picks