Beginners Guide to yum Configuration

All software on a Linux system is divided into packages that can be installed, uninstalled, upgraded, queried, and verified. CentOS/RHEL systems use the Red Hat Package Manager (RPM) to facilitate the installation, upgrade and removal of software packages.

CentOS/RHEL also provides the yum(Yellowdog Updater, Modified) utility, which works with RPM packages. When yum installs or upgrades a software package, it also installs or upgrades any package dependencies. The yum utility downloads package headers and packages from repositories. Repositories are storage locations from which software packages can be retrieved and installed.

Yum Configuration Files

The main configuration file for yum is /etc/yum.conf. Configuration files that define repositories are in the /etc/yum.repos.d directory. An example of /etc/yum.conf follows here:

# cat /etc/yum.conf
[main]
cachedir=/var/cache/yum/$basearch/$releasever
keepcache=0
debuglevel=2
logfile=/var/log/yum.log
exactarch=1
obsoletes=1
gpgcheck=1
plugins=1
installonly_limit=3

Global configurations are defined in the [main] section:

Parameter Purpose
cachedir The directory to store downloaded packages
keepcache Set to 0 to indicate to remove packages after installing them.
debuglevel The amount of information logged, from 0 to 10
logfile The yum log file
exactarch When set to 1, yum updates packages only with packages of the same architecture.
obsoletes When set to 1, yum replaces obsolete packages during an update.
gpgcheck When set to 1, yum checks the GPG signatures to verify authenticity of the packages. The gpgkey directive specifies the location of the GPG key.
plugins When set to 1, enables yum plugins that extend functionality.
installonly_limit The maximum number of versions that can be installed simultaneously for any single package

yum Repositories

Linux stores information about each repository in a separate file in the /etc/yum.repos.d directory. The following is an example:

# ls -lrt /etc/yum.repos.d
total 20
-rw-r--r-- 1 root root  733 Jul 27 18:09 rhel7.2.repo
-rw-r--r-- 1 root root  358 Nov  5 14:00 rhel7.3.repo

The repo files define which repositories to use. Each repo file includes specifications for several related repositories. For example,

[epel]
name=Extra Packages for Enterprise Linux 7 - $basearch
baseurl=http://download.fedoraproject.org/pub/epel/7/$basearch
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7

The directives in the repo files include:

directives Purpose
name Describes the repository
baseurl Is the location of the main repository (http://, ftp://, or file://)
enabled When set to 1, yum uses the repository. The repository is disabled if set to 0.

yum repositories can also be locally accessible, not just over the Internet. Local yum repositories are created by using the createrepo command and then setting baseurl to the local directory.

The yum utility is often the fastest way to perform package management tasks. It provides capabilities beyond those provided by rpm and by graphical package management tools. There are many yum commands, but the following provides examples of common tasks.

Listing Packages

There are several yum commands to list packages in any repository enabled on your system or installed. You can list specific types of packages as well as refine your list with a package specification of any package’s name, architecture, version, or release.

To list all packages in all the repositories and all the packages installed on your system, use the following command:

# yum list

To list all the packages installed on the system, use the following command:

# yum list installed

To list all the packages available to be installed in any enabled repository on your system, use the following command:

# yum list available

The following example finds the name of the package that a file (for example, /etc/sysconfig/atd) belongs to:

# yum provides /etc/sysconfig/atd 
at-3.1.13-17.el7.x86_64 : Job spooling tools 
...

Checking for Updates

To see which installed packages on your system have updates available, use the following command:

# yum check-update

The package name plus architecture, the version of the updated package, and the repository (or
ULN channel) are displayed. Entering yum list update returns the same output.

Updating Packages

You can choose to update a single package, multiple packages, or all packages at once. If any dependencies of the package (or packages) have updates available, they are updated also.

Updating a Single Package

To update a single package, use the following command syntax:

# yum update package_name

For example, to update the bind-libs package, enter:

# yum update bind-libs

yum checks for dependencies, displays dependencies resolved and a transaction summary, prompts “Is this ok [y/N]“, waits for your response, and then downloads and installs the package and any dependent packages needed. Use yum -y to bypass the prompt.

Updating All Packages

To update all packages and their dependencies, enter yum update (without any arguments):

# yum update

Installing Packages

To install a new package together with any package dependencies, use the following syntax:

# yum install package_name

For example, to install the zsh package, enter:

# yum install zsh

Updating and Installing Kernels

You do not need to worry about the distinction between installing and upgrading a kernel package when you use yum. yum always installs a new kernel regardless of whether you are using yum update or yum install.

Removing Packages

To remove a package, use the following syntax:

# yum remove package_name

For example, to remove the zsh package, enter:

# yum remove zsh
Related Post