Tuesday, March 31, 2020

YUM Package Manager

Yum is one of the relatively newer methods of software management on Linux systems.   It has been around since 2004.  Yum is essentially a wrapper program for RPM, with great enhancements.  It has become widely used and is prominent because major Linux vendors decided to concentrate on their more profitable commercial product offerings.  Yum has changed and enhanced the traditional approach to package management on RPM-based systems.  Popular large sites that serve as repositories for open source software have had to retool slightly to accommodate "Yumified" repositories.  

Yum is an automatic updater and package installer/remover for RPM systems.  It automatically computes dependencies and figures out what things should occur to install packages.  It makes it easier to maintain groups of machines without having to manually update each one using RPM.

The yum command makes it easy to add and remove software packages in your system.  It maintains a database regarding the appropriate way to add, upgrade, and remove packages.  This makes it relatively simple to add or remove software with a single command.

The main configuration file for yum is /etc/yum.conf   .  Other configuration files may be stored under /etc/yum.repos.d subdirectory that points to the yum-enabled software repository.  

A typical yum.conf file will look like:
linux123.us.company.com: / >
linux123.us.company.com: / >
linux123.us.company.com: / > cat /etc/yum.conf
[main]
cachedir=/var/cache/yum
keepcache=0
debuglevel=2
logfile=/var/log/yum.log
pkgpolicy=newest
distroverpkg=redhat-release
tolerant=1
exactarch=1
obsoletes=1
gpgcheck=1
plugins=1

# Note: yum-RHN-plugin doesn't honor this.
metadata_expire=3600

# Default.
# installonly_limit = 3

# PUT YOUR REPOS HERE OR IN separate files named file.repo
# in /etc/yum.repos.d
linux123.us.company.com: / >
linux123.us.company.com: / >

The first line [main] implies that this file is the main configuration file for this service.
[main]

The cachedir directive specifies the directory where yum downloads are stored.
cachedir=/var/cache/yum

If you change the keepcache setting, you can save downloaded RPMs in a /var/cache/yum subdirectory associated with the RHN software channel or repository.
keepcache=0

The debuglevel directive specifies the level of messages specified in the file associated with the logfile directive.  Since multiple packages may be associated with each version of RHEL, the pkgpolicy directive specifies that yum uses the latest version.
debuglevel=2
logfile=/var/log/yum.log
pkgpolicy=newest

The distroverpkg directive shown takes the version number from the /etc/redhat-release file.
distroverpkg=redhat-release

The tolerant directive shown allows yum to work even with minor errors.  For example, if you run yum install on a list of packages, and one is already installed, the command still proceeds.

tolerant=1

Most Linux distributions are architecture-dependent; the following directive makes sure that yum downloads correspond to your CPU architecture.
exactarch=1

During a yum update command, the following directive checks for and uninstalls any obsolete packages.
obsoletes=1

Naturally, to confirm appropriate packages, it's important for yum to check the GPG key, as below.
gpgcheck=1

The following directive includes plug-ins as defined in the /etc/yum/pluginconf.d and /usr/lib/yum-plugins directories as part of the yum configuration.
plugins=1

To make sure the header data downloaded from the RHN (and any other repositories) are up to date, the metadata_expire directive specifies a lifetime for headers.  In other words, if you have not used the yum command in one hour, the next use of the yum command downloads the latest header information.
metadata_expire=3600

Finally, the following notes the default location for configuring other repositories.  Even though it's in comments, the /etc/yum.repos.d directory is the default location for these third-party repository configuration files.
# PUT YOUR REPOS HERE OR IN separate files named file.repo
# in /etc/yum.repos.d

Regular RHN repositories are defined in various python-based configuration files in the /usr/lib/yum-plugins directory.

Install Mode:
There are two basic installation commands in yum.  If you have not installed a particular package before, or if you want to update it to the latest stable version, run the yum install <packagename> command.  For example, if you are checking for the latest version of the Samba RPM, the following command will update it or add it if it is not already installed on your system.
# yum install samba

If you just want to keep the packages on your system up to date, run the yum update <packagename> command.  For example, if you already have the Samba RPM installed, the following command makes sure it's updated to the latest version.
# yum update samba

Note: If you have not installed Samba, this command does not add it to your installed packages.

The yum update command by itself is powerful; if you want to make sure that all installed packages are updated to the latest stable versions, run the following command.
# yum update

The yum update command may take some time as it communicates with the RHN, with all dependencies.

But what if you don't know what you want to install ?  For example, if you want to install the Evince document reader, the yum whatprovides <filename> command can help.  To search for all instances of the Evince document reader, you can run the following command.
# yum whatprovides evince

It lists all instances of the evince file, with the associated RPM package.  It works like the locate command; in other words, partial file names also work with the yum whatprovides command.  Once you identify the package you need to install, you can proceed with the yum install <packagename> command.

By default, Yum tries to access repositories that are located somewhere on the Internet.  Therefore your system needs to be able to access the Internet to use Yum in its default state.  You can also create your own local software repository on the local file system or on your local area network (LAN) and Yumify it.  Simply copy the entire contents of the distribution media (DVD/CD) somewhere and run the yum-arch command against the directory location.

No comments:

Post a Comment