jump to navigation

Yum repositories on RHEL – CentOs Cheatsheet November 15, 2010

Posted by Tournas Dimitrios in Linux.

Yum is just a front end for the rpm – package management .If you use a version of Linux that comes with Yum, you are more than likely familiar with it. For those of you who aren’t, it’s a program that can either be ran with or without a GUI and that is made to install, remove and update packages on a system. This article demonstrates the basic commands that I use to handle packages and repositories on my CentOs box ..

Basic Yum commands
Is a software already installed on my system ? 

yum list install software-name

yum list install software-name1 software-name2

Installing with yum : yum install PACKAGE-name
Installing local rpm’s with yum : yum localinstall PACKAGE-name 

Is used to install a  local rpm file . If required the enabled repositories will be used  to
resolve  dependencies. Note that the install command will do a local install, if given a filename.

Search for software : yum search software-name or  *string
Updating software : yum update PACKAGE-name
Uninstalling software : yum remove PACKAGE-name
List available updates for installed packages:yum list updates
Update the whole system: yum update
Find out which package a file belongs to: yum provides ‘foo’
Yum has package groups that install big clumps of stuff at once. You can see a list of these:yum grouplist 

These are managed with almost the same commands as individual packages, with the group’s name enclosed in single quotes: yum groupinstall ‘name of grouplist’   ,   yum groupupdate ‘ name of grouplist ‘

yum groupdelete ‘name of grouplist’

Run automatic daily updates:chkconfig –level 345 yum on; service yum start

By default, Yum queries your remote repositories every single time you run it, which are listed in /etc/yum.repos.d. This can get boring pretty quickly because it takes time to download fresh package lists. An alternative is to create a local Yum cache. To do this, add this line to /etc/yum.conf: keepcache=1  Then run yum -C ‘options’ when you want to hit the local cache instead of fetching fresh data.

Installing a repository on your Yum repository list is made through the rpm command , read this article for a detailed description .These files/directories are important to notice :

  • /etc/yum.conf : main configuration file
  • /etc/yum/yum-updates.conf : Configuration file for enable/disable automatic update/installation
  • /etc/yum.repos.d/ : home dir for all your repos
  • /etc/pki/rpm.gpg/ : this dir contains the keys of all installed repos
  • /var/log/yum.log : Yum creates an index of installation/update/delete of a package . It is a handy way to find when a package was installed / deleted from our box : less /var/log/yum.log  | grep -i nagios .This reveals all information when nagios was installed / updated / and or removed .

The following table lists the commands that can be used to manipulate the Yum repositories :

Handling your Yum repositories (click on thumbs)
What repos are installed on your box :ls -l  /etc/yum.repos.d/
What repos are enabled on your box  List All Repositories and Check Repository ID’s:yum repolist
What repository keys are installed on your box :ls -l  /etc/pki/rpm-gpg/
Permanently removing a repository from your box :rpm -e  some-repository-rpm-package-name 

To find out the name of repo package : rpm -qa | grep -i epel

The result on my box is :   epel-release-5-4

so :  rpm -e epel-release-5-4

Disable permanently  YUM Repo (Repository) .Each repo has a configuration file inside  /etc/yum.repos.d/ . So open this file with your favorite text editor and change enabled to 0 .Please note the first line inside this file , the name in the brackets [] is the repo-name vs [epel] 

Alternatevily rename the name of the repo config file

mv /etc/yum.repos.d/repo-file.repo /etc/yum.repos.d/repo-file.repo.bak

Enable disabled repo quickly with YUM (temporarely) :yum – -enablerepo=repo-name install some-package 

yum – -disablerepo=repo-name install some-package

example : yum – -disablerepo=epel install some-rpm-package

Query Available Packages From Selected YUM Repository Disable all repositories and then enable just selected repo.yum – -disablerepo=”*”  – -enablerepo=”google” list available
# The  repCentOS-Media.repo is used to mount the default locations for a CDROM / DVD on  CentOS-5.  You can use this repo and yum to install items directly off the  DVD ISO .  To use this repo, put in your DVD and use it with the other repos too: 

yum –enablerepo=c5-media [command]

# or for ONLY the media repo, do this:

yum –disablerepo=\* –enablerepo=c5-media [command]

Handling groups of packages :

Some applications or development environments are made from many packages . For example the KDE desktop environment is made of 22 packages . So instead of handling these packages separetaly , during installing or removing of KDE , yum provide us with nice utilities to handle these packages as a whole .

Yum  groups
yum grouplist List all available package groups
yum  groupinfo   [Name of package group] Displays  information for a specific package group
yum groupinstall  [Name of package group] Installing of a package group
yum groupremove  [Name of package group] Removing of a package group

Find out from what repo your installed packages are :

Sometimes it is necessary to know from what repository a specific package is installed . The package “yum-utils” contains the  ” repoquery ” command that get for us this information . First install the package with the following command : ” yum install  yum-utils ”  .

Now run repoquery -i [your-package-name] .

Cleaning the catche of  Yum

The yum package manager maintains a cache of headers and files in /var/cache/yum. Remove obsolete packages, free up disk space this is a really important to run these commands mentioned here in this post to keep your system performing really good and reduce lagging time for installing updates.

This guide is for distributions using yum package installer “RPM package manager” like Fedora, CentOS and openSUSE.

Pros and Cons :
Pros: Removing unneeded packages will improves machine performance and Free up disk space.

Cons: Removing this packages you might need in the future, sometimes you need it in case you have similar broken packages to replace with, just to save some time for installing it directly from old ons instead of downloading those packages again.

By default, yum retains the packages and package data files that it downloads, so that they may be reused in future operations without being downloaded again. To purge the package data files, use this command:
$ yum clean headers

Run this command to remove all of the packages held in the caches:
$ yum clean packages

To clean the metadata files use this command:
$ yum clean metadata

This cache can grow rather large over time, and can be cleaned with the yum “clean” option. Clean all cached files and packages from active repository.
$ yum clean all

When using these commands, at the prompt, enter the password for the root account.

*Purging cached files causes those files to downloaded again the next time that they are required. This increases the amount of time required to complete the operation.*

Read this :


1. Jason Pirkey - December 8, 2010

Nice, thanks! I knew the rest of them, but could not figure out how to get yum to determine what repo a package belonged to. So thanks for providing that!


2. linuxgeek - February 19, 2011

Thanks for putting this cheatsheet together!

I have a question, given a package name, do you know how I can find out which group(s) that package belongs to?

tournasdimitrios1 - February 19, 2011

Hi ,
Example : (for “nologin”)
#whereis nologin —> /sbin/nologin
#rpm -q –whatprovides /sbin/nologin —>util-linux-xxx.xxx
#rpm -qi util-linux-xxx
#rpm -qa –qf ‘%{NAME}-%{VERSION}-%{RELEASE}.%{ARCH}: %{GROUP}\n’
#Of course with grep: “previous command” |grep -i util-linux
(note: – -whatprovides , – -qf)
Let me know if this helped you

3. How to List the Files Installed by the YUM Package Manager « Tournas Dimitrios - November 2, 2012

[…] Yum repositories on RHEL – CentOs Cheatsheet […]

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s