yum: repositories, EPEL and common commands
yum cheat sheet for RHEL/CentOS: EPEL, CentOS 8 vault, updates, cache and metadata troubleshooting.
Quick reference for managing yum repositories on RHEL-family systems (RHEL, CentOS, Oracle Linux): system information, EPEL, searching and installing packages, security updates, cache cleaning and common repository errors.
System information
uname -a
cat /etc/*release*
Get the distribution package name, the release version and the architecture used in repository URLs ($releasever, $basearch):
distro=$(sed -n 's/^distroverpkg=//p' /etc/yum.conf)
releasever=$(rpm -q --qf "%{version}" -f /etc/$distro)
basearch=$(rpm -q --qf "%{arch}" -f /etc/$distro)
rpm -qf /etc/*-release
rpm -q --qf "%{name}" -f /etc/redhat-release
CentOS 8 end of life: switch to the vault
CentOS 8 reached end of life (see the CentOS Linux EOL page). The following commands comment out the mirror list and point the repositories to the vault:
sudo yum clean all
sudo rm -rf /var/cache/yum/*
sudo sed -i 's/mirrorlist/#mirrorlist/g' /etc/yum.repos.d/CentOS-Linux-*
sudo sed -i 's|#baseurl=http://mirror.centos.org|baseurl=http://vault.centos.org|g' /etc/yum.repos.d/CentOS-Linux-*
sudo yum update
EPEL
Install the EPEL repository, refresh the repository list and install a package from it:
sudo yum install epel-release
yum repolist
yum install pkg1
Manual installation (EPEL 7):
cd /tmp
wget https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
ls *.rpm
sudo yum install epel-release-latest-7.noarch.rpm
On RHEL 8, enable the CodeReady Builder repository first, then install the EPEL release package:
subscription-manager repos --enable codeready-builder-for-rhel-8-$(arch)-rpms
dnf install https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm
List the packages available from EPEL only:
sudo yum --disablerepo="*" --enablerepo="epel" list available
sudo yum --disablerepo="*" --enablerepo="epel" list available | grep 'package'
Remove EPEL:
yum remove epel-release
yum update
or
rm /etc/yum.repos.d/epel.repo
yum update
Search, inspect and install a package
sudo yum search htop
repoquery -i htop
sudo yum info htop
sudo yum install htop
Local installation of an RPM file:
sudo yum localinstall sample_file.rpm
sudo rpm -i sample_file.rpm
Find the package that owns a file:
yum whatprovides '*filename'
Updates
yum updateinfo list security
yum updateinfo security
yum updateinfo
yum check-update
yum list updates
# exclude packages from an update
yum update --exclude=kernel* --exclude=httpd
yum upgrade also removes obsolete packages.
History and duplicates
yum history
yum history info 2
yum history undo 7
package-cleanup --dupes
Repositories
yum repolist
yum repolist enabled
yum repolist disabled
yum repolist all
yum repolist --verbose
yum makecache
List the packages installed from a given repository (here epel):
yum list installed | grep @epel
sudo yum install yum-utils
yumdb search from_repo epel
repoquery -a --installed --qf "%{ui_from_repo} %{name}" | grep '^@epel'
Repository definitions live in /etc/yum.repos.d/:
ls /etc/yum.repos.d/ -altr
Before editing or removing a repository file, keep a copy and check the installed kernel:
uname -a
lsb_release -a
rpm -qa | grep kernel
Cache
The cache location is set in /etc/yum.conf, in the [main] section:
[main]
cachedir=/var/cache/yum/$basearch/$releasever
Cleaning the cache:
# purge old package information
yum clean packages
# clean cached XML metadata
yum clean headers
yum clean metadata
# clean everything at once
yum clean all
Troubleshooting: EPEL metadata cannot be retrieved
Typical error:
Loaded plugins: product-id, refresh-packagekit, security, subscription-manager
This system is receiving updates from Red Hat Subscription Management.
Error: Cannot retrieve repository metadata (repomd.xml) for repository: epel. Please verify its path and try again
Possible fixes (see this Stack Overflow question and this Unix & Linux question):
-
In
/etc/yum.repos.d/epel.repoand/etc/yum.repos.d/epel-testing.repo, comment out all lines starting withmirrorlist=and uncomment all lines starting withbaseurl=. -
Run with debug output and look for
PYCURL ERROR 77 - "Problem with the SSL CA cert (path? access rights?)":URLGRABBER_DEBUG=1 yum check-update 2> debug.log -
If the SSL CA certificate is the cause, reinstall the certificates:
yum --disablerepo="epel" reinstall ca-certificates
Notes
yumis replaced bydnfon recent releases (RHEL 8 and later); most commands above have adnfequivalent.- The vault repositories are archives: they receive no new updates.