Linux Admin Reference : Yum Quick Reference – Redhat Enterprise Linux

Yum or “Yellow dog Update, Modified” is a package manager that was developed by Duke University to improve the installation of RPMs.

Yum searches several repositories for packages and their dependencies so they may be installed together in an effort to alleviate dependency issues. Red Hat Enterprise Linux 4/5/6 uses Yum to fetch packages and install RPMs.

Yum uses a configuration file at /etc/yum.conf. There are multiple ways by which you can install a repository on the system and install/update packages :

  • Add Locally Mounted DVD / ISO image as yum repository
  • Setup a new repository having packages populated from ISO’s downloaded from RHN
  • Register the system on RHN and subscribe to the channels depending on the subscription you have.
  • Registering a third party repository ( Non Redhat Supported)
In this Post, I will be Covering below points for your quick reference about YUM

1. YUM BASIC usage ( as root) 
2. Configuring Yum / up2date repository to use locally mounted DVD
3. Configure Customized repository, consists only the packages tested for your environment
4. Configuring YUM to install the packages from the RHN subscribed Channels
5. Configuring a third-party repository ( Non-Redhat)
6. Configure Yum to list only the packages available in my local repository
7. How to install all related packages together using YUM?
8. How to Exclude Kernel related packages to automatically update, while updating my linux server using yum?
9. How do fix yum errors Like ” is duplicate of ?
10. Understanding YUM plugins

1.  YUM BASIC usage ( as root) :

1) Install a package                            :        yum install package

Example:     # yum install httpd

2) Remove a package                      :        yum remove package

Example:     # yum remove httpd

3) Update a package                        :         yum update package

Example:     # yum update httpd

4) Search for a package                 :         yum search package

Example:     # yum search httpd

5) Find information about a package:            yum info package

Example:     # yum info httpd

6) List packages containing a certain term:    yum list term

Example:    # yum list httpd

7) Find what package provides a particular file:  yum whatprovides ‘path/filename’

Example:     # yum whatprovides ‘etc/httpd.conf’

8) Update all installed packages with kernel package :     yum -y update

Example:        # yum -y update

9) To update a specific package:      yum -y update

Example:     #  yum -y update openssh-server

 

2. Configuring  Yum / up2date repository to use locally mounted DVD

Procedure for RHEL4

In /etc/sysconfig/rhn/sources, comment out the following line:

# up2date default

This line needs to be commented out otherwise up2date will keep on looking for information using the Red Hat Network first. Next, in the same file, create a line like the following:

dir mydvdrepo /media/cdrom/RedHat/RPMS

Note: The CD/DVD must be mounted and available in the directory /media/cdrom/ and the path must point to the directory containing the RPMS.

Procedure for RHEL 5

Note: Please make sure YUM package version is yum-3.2.8-9 or higher. Earlier Versions have bugs )

Create a dvd.repo text file in /etc/yum.repos.d/with the following content :

[dvd]
mediaid=1170972069.396645*
name=DVD for RHEL5
baseurl=file:///media/RHEL_5%20i386%20DVD/Server
enabled=1
gpgcheck=0

[dvd-cluster]
mediaid=1170972069.396645
name=DVD for RHEL5 – Cluster
baseurl=file:///media/RHEL_5%20i386%20DVD/Cluster
enabled=1
gpgcheck=0

[dvd-cluster-storage]
mediaid=1170972069.396645
name=DVD for RHEL5 – ClusterStorage
baseurl=file:///media/RHEL_5%20i386%20DVD/ClusterStorage
enabled=1
gpgcheck=0

[dvd-vt]
mediaid=1170972069.396645
name=DVD for RHEL5 – VT
baseurl=file:///media/RHEL_5%20i386%20DVD/VT
enabled=1
gpgcheck=0

 

Note 1 : DVD repo only supports only base rpm packages under the /server directory, and the remaining repo will support the additional packages from the DVD.

Note 2:  For example for RHEL 5.5 version baseurl line should look like baseurl=file:///media/RHEL_5.5%20i386%20DVD/Server’

Note 3: The mediaid= value comes from the .discinfo file located in the root of the DVD.

 

Procedure for RHEL 6

Mount RHEL 6 ISO to /media/rhel6

# mount -o loop RHEL6.0-20101111.0-Server-x86_64-DVD.iso /media/rhel6

Copy media.repo file from the RHEL 6 ISO to /etc/yum.repos.d/

# cp /media/rhel6/media.repo /etc/yum.repos.d/rhel6.repo

Configure the repo file to point to the /media/rhel6

# vi /etc/yum.repos.d/rhel6.repo

Add following line

baseurl=file:///media/rhel6/Server

Ifyou want to configure repository for HighAvailability , LoadBalancer , ResilientStorage and ScalableFileSystem then you can add following lines in rhel6.repo file

[dvd-HighAvailability]
mediaid=1289489697.332694
name=DVD for RHEL6 – HighAvailability
baseurl=file:///media/rhel6/HighAvailability
enabled=1
gpgcheck=0

[dvd-LoadBalancer]
mediaid=1289489697.332694
name=DVD for RHEL6 – LoadBalancer
baseurl=file:///media/rhel6/LoadBalancer
enabled=1
gpgcheck=0

[dvd-ResilientStorage]
mediaid=1289489697.332694
name=DVD for RHEL6 – ResilientStorage
baseurl=file:///media/rhel6/ResilientStorage
enabled=1
gpgcheck=0

[dvd-ScalableFileSystem]
mediaid=1289489697.332694
name=DVD for RHEL6 – ScalableFileSystem
baseurl=file:///media/rhel6/ScalableFileSystem
enabled=1
gpgcheck=0

 

3. Configure Customized repository, consists only the packages tested for your environment

There are two methods for doing this:

Method 1 :

1. Create the folder that will hold the repository:

# mkdir -p /usr/share/repository

2. Create the RPM repository, and copy all the RPMs you want to use into that directory:

# cd /usr/share/repository
# createrepo .
# yum clean all
Note: The createrepo package needs to be installed on the system in order to run the following commands.

3. Create the file /etc/yum.repos.d/file.repo as follows:

# cat /etc/yum.repos.d/file.repo
[RHEL_Repository]
baseurl=file:///usr/share/repository
enabled=1

4. Show the package list:

# yum list

5. Now you can install any packages you want, for example:

# yum install httpd

Method 2  : There is another way to build the repository without copying all the RPMs to disk. In the ISO file there are repo data directories, and you can use these directly.

1. Mount the ISO file:

# mount -o loop,ro rhel-X-server-i386-dvd.iso /mnt/iso

2. Create the file /etc/yum.repos.d/file.repo:

# cat /etc/yum.repos.d/file.repo
[RHEL_Server_Repository]
baseurl=file:///mnt/iso/Server
enabled=1

[RHEL_VT_Repository]
baseurl=file:///mnt/iso/VT
enabled=1

 

4. Configuring YUM to install the packages from the RHN subscribed Channels

 To download software, updates, and security errata, your system should be registered to RHN Classic.

Step1 : Register System to RHN

 We have two commands  to register the system in RHN network so the system can get updates from RHN. 

 Method 1:  

Using  an Interactive command ,  rhn_register, where the registration program will ask the details one by one .

We should have  /etc/sysconfig/rhn/up2date file configured, before we use rhn_register command

# vi /etc/sysconfig/rhn/up2date 
serverURL=https://xmlrpc.rhn.redhat.com/XMLRPC 
sslCACert=/usr/share/rhn/RHNS-CA-CERT

Note: we can get /usr/share/rhn/RHNS-CA-CERT file by installing “rhn_client_tools” package

Then use the below command to go through an interactive process , to register the system into RHN

#rhn_register

 

Method 2.  

Using a non-interactive command, rhnreg_ks , which allow us to key-in all the related information with single command. And mostly, we use this command to register the system to RHN using an activation key that we have already created as given below

 

  1. Log in to your RHN account or Satellite server as a user with administrative privileges
  2. Go to Subscriptions -> Classic Management -> Registered Systems -> Activation Keys -> Create New Key
  3. Fill in the Description field with something meaningful (like “marketing,” or “developer”)
  4. Set the Usage Limit if you wish to enforce a maximum number of systems that can use this key
  5. Set Add-On Entitlements to “Provisioning” or “Management” depending on the needs of this system
  6. Set Universal Default. Universal Default means that this key will be used for any system registered to this account that does not specify a key. Set this to “yes” if you want this key to be the default key; set this to “no” if you want this key to be used only when specified

 

Example : 

# rhnreg_ks –profilename=gurkulindia_rhel_system –activationkey=1-dfasdf345345sdfasdfdas275c93

or

# rhnreg_ks –profilename=gurkulindia_rhel_system –username=gurkuluser –password=abc1234

Note: if you rhnreg_ks with user and password information, that information might be stored in the shell history.So don’t forget clear the history using history -c ( it will clear entire system history)

 
 

STEP 2: Installing/Updating Packages using RHN

 
For RHEL5/RHEL6 :  Use the following command to update the operating system:

# yum update

To install a specific package, such as vsftpd, use the following command:

# yum install vsftpd

To update a specific package, such as bind, use the following command:

# yum update bind

For RHEL 4:  Launch the interactive Red Hat Update Agent with the following command:

# up2date

For a command line interface, use up2date-nox. To update non-interactively, use the following command:

# up2date-nox –update

To install a specific package, such as vnc, use the following command:

# up2date vnc

To update a specific package, such as ntp, use the following command:

# up2date -u ntp

 

5. Configuring a third-party repository ( Non-Redhat) 

 

Method 1 : Configuring third part repository by Installing  the  third party repository release package to enable yum to download the software.

For example, Extra Packages for Enterprise Linux (or EPEL) has an epel-release package that includes gpg keys for package signing and repository information.

# wget -c http://download.fedoraproject.org/pub/epel/6/i386/epel-release-6-5.noarch.rpm
# rpm -ivh epel-release-6-5.noarch.rpm
warning: epel-release-6-5.noarch.rpm: Header V3 RSA/SHA256 Signature, key ID 0608b895: NOKEY
Preparing… ########################################### [100%]
1:epel-release ########################################### [100%]

# yum repolist
Loaded plugins: rhnplugin
repo id repo name status
epel Extra Packages for Enterprise Linux 6 – x86_64 5,979
rhel-src Red Hat Enterprise Linux 6Server – x86_64 – Source 2,640
rhel-x86_64-server-6 Red Hat Enterprise Linux Server (v. 6 for 64-bit x86_64) 5,043
repolist: 13,662

Method 2: Manually Crating Customized Non-Redhat Package Repository

Create a file named /etc/yum.repos.d/epel.repo as following:

# vi /etc/yum.repos.d/epel.repo
[epel]
name=Extra Packages for Enterprise Linux 5 – $basearch
baseurl=http://download.fedoraproject.org/pub/epel/5/$basearch
enabled=1
gpgcheck=1

#gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL
gpgkey=http://download.fedora.devel.redhat.com/pub/epel/RPM-GPG-KEY-EPEL

All of this configuration information should be available on the site for which the yum repo is being created. Then import the gpg key for the repository as follows:

# rpm –import http://download.fedora.devel.redhat.com/pub/epel/RPM-GPG-KEY-EPEL

 

6. Configure Yum to list only the packages available in my local repository

By Default “yum list” will display all the packages both from local repository and the base channel enabled in /etc/yum/pluginconf.d/rhnplugin.conf.

If we want to display only packages available locally and ignore RHN, then we have to disable the base channel as mentioned below

 Edit /etc/yum/pluginconf.d/rhnplugin.conf  and disable base channel:

[main]
enabled = 0
gpgcheck = 1

# You can specify options per channel, e.g.:
#
#[rhel-i386-server-5]
#enabled = 1
#
#[some-unsigned-custom-channel]
#gpgcheck = 0

 

7. How to install all related packages together using YUM?

YUM supports grouping all the related rpm packages together for ease of installation. The group data is stored in a file called “comps.xml”  under the repodata folder.

Process to Define a custom package group:

 

1. Create the RPM repository, and copy all the RPMs you want to use into that directory:

# mkdir -p /usr/share/repository
# cp *.rpm /usr/share/repository

2. Run createrepo command to create the repodata folder :

# cd /usr/share/repository
# createrepo .

Note: The createrepo package needs to be installed on the system

3.  Now to create the Groups file, by Creating the comps.xml file under repodata folder :

<comps>
<!– <meta> –>
<!– Meta information will go here eventually –>
<!– </meta> –>
<group>
<id>gurkulgroup</id>
<name>gurkulgroup</name>
<default>true</default>
<description>Description of group goes here</description>
<uservisible>true</uservisible>
<packagelist>
<packagereq type=”mandatory”>package1
<packagereq type=”default”>package2
<packagereq type=”optional”>pacakge3
</packagelist>
</group>
</comps>

 

Each group has an id, user visibility value, name, description, and package list. In the package list, there are three types package:

  • mandatory   :     the packages marked as mandatory are always installed if the group is selected.
  • default           :     the packages marked default are selected by default if the group is selected.
  • optional        :     the packages marked optional must be specifically selected even if the group is selected.

4. Rerun createrepo so that group assignments are taken into account :

# createrepo -g repodata/comps.xml .

5. Create the file /etc/yum.repos.d/file.repo as follows:

# cat /etc/yum.repos.d/file.repo
[myrepo]
name=My Repo
baseurl=file:///usr/share/repository
enabled=1

6. To test :

#yum clean all
# yum –noplugins groupinfo gurkulgroup

Install   Package Groups:

To list all  available package groups:

# yum grouplist 

Sometime, grouplist command can’t list all the groups that are provided when installing RHEL installation CD. And to  list all  groups, including hidden groups, run the following command:

# yum grouplist hidden

To install the packages under a specific group you can execute the command :

# yum groupinstall “”

Example:

# yum groupinstall “Chinese Support” 

# yum groupinstall “KDE (K Desktop Environment)”

 

8.  How to Exclude Kernel related packages to automatically update, while updating my linux server using yum?

 

The up2date command in RHEL 4 excludes kernel updates by default. The yum in RHEL 5 includes kernel updates by default.

To skip installing or updating kernel or other packages while using the yum update utility in RHEL 5 and 6, use following options

Via command line (temporary):

# yum update –exclude=PACKAGENAME

For example, to exclude all kernel packages:

# yum update –exclude=kernel*

To make permanent changes, edit the /etc/yum.conf file. Follow these steps:

# vi /etc/yum.conf

Add a new line in the [main] section like this: exclude=package1,package2

For example:


gpgcheck=1
plugins=1
installonly_limit=3
exclude=kernel*
Save file.

 

9. How do fix yum errors  Like   “package_version-1_1  is duplicate of  package-version-1” ?

Use package-cleanup to remove duplicates.

# package-cleanup –dupes
# package-cleanup –cleandupes

Update the system.

# yum update

 

10.  Understanding YUM plugins

 Yum provided plug-ins that extend and enhance yum functionality. Some plugins installed by default, and yum always gives the plug-ins used whenever we run the yum command as shown below

# yum info yum Loaded plugins: product-id, refresh-packagekit, subscription-manager

:::::::::[output truncated]::::::::::::

Enable/Disable YUM plugins

Open ‘/etc/yum.conf’.

To disable yum plugins, change the value for plugins to 0.

          plugins = 0

After changing that,  clear  the yum cache by executing the following command.

          # yum clean all

To enable yum plugins, change the value for enabled to 1

 

Protecting YUM Source Repository using yum plugins

Red Hat Enterprise Linux (5 and later version) comes with a tool to manage packages using repositories, yum. However, if you use two different repositories, each holding a different version of the same package, only the latest of the two will be installed if you use yum to update that package. This can lead to problems if the third party repository contains a newer version of a core system package than the Red Hat repository.

By using below yum plug-in , we can protect yum source packages from overriding by other available repositories in the server.

  • Yum plugin, for RHEL5 :                yum-protectbase
  • Yum plugin, for RHEL 6:                yum-plugin-protectbase

Using the plugin to protect a repository:

Go to the repository configuration file located in ” /etc/yum.repos.d/repository.repo ” and add the line “protect=1” as shown in the example:

[repository]
::: output truncated:::::
protect=1
:::: output truncated:::::

Using the plugin to protect particular RHN channel:

Edit the file  “/etc/yum/pluginconf.d/rhnplugin.conf” and add “protect=yes” line, under the channel we want to protect, as shown in below example

[rhel-x86_64-server-5]
enabled = 1
protect = yes

Ramdev

Ramdev

I have started unixadminschool.com ( aka gurkulindia.com) in 2009 as my own personal reference blog, and later sometime i have realized that my leanings might be helpful for other unixadmins if I manage my knowledge-base in more user friendly format. And the result is today's' unixadminschool.com. You can connect me at - https://www.linkedin.com/in/unixadminschool/

You may also like...

13 Responses

  1. Gaurav Gupta says:

    Often we see that Yum hungs while we give yum list |grep -i or issue other yum command. The ssh session also hungs due to this. Is there any command to resolve the issue ?

  2. Kennedy says:

    Good Article – Very useful stuff. Cool Stuff. Keep it coming and Thanks a billion for sharing.

  3. Ramdev Ramdev says:

    Gaurav, Whenever it hung, you should  trace the process on different SSH session, to find what is locking the process.    # strace -p

  4. Prashant Dhuri says:

    Nice post…keep it up…Thx

  5. prashant says:

    Really useful stuff. I used to visit your website to seek help. Your articles are really admiring.

  6. Jeet says:

    Thanks a lot Ram, nice article, really useful for all.

    I would like to know is it possible to have a consolidated dedicated YUM Server for all OS like RHEL5, RHEL6, RHEL6.2, RHEL6.3.

  7. boopathi says:

    Hi,

    I really appreciate efforts. Thanks for spending your valuable time time with us. 

  8. FMK says:

    Well put and very helpful. Will recommend.

  9. ayyappan says:

    It is very usefull in realtime.
    Thank you so much…..

  1. May 27, 2013

    […] Earlier we already posted a detail troubleshooting reference for YUM  and the link is “Yum Quick Reference for Everyone“ […]

  2. September 16, 2015

    […] Read – Yum Quick Reference Guide […]

What is in your mind, about this post ? Leave a Reply

Close
  Our next learning article is ready, subscribe it in your email

What is your Learning Goal for Next Six Months ? Talk to us