CentOS/RHEL 6/7
yum install epel-release
CentOS/RHEL 8
dnf install epel-release
This command will work most of the times but I have faced an issue with some versions where this might not work. So if this does not work for you, then you can use the second method.
2- Using RPM packages
RHEL/CentOS 6:
yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-6.noarch.rpm
RHEL/CentOS 7:
yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
Epel also recommends for RHEL 7, to enable the optional, extras, and HA repositories since EPEL packages may depend on packages from these repositories, using the following command,
subscription-manager repos –enable “rhel--optional-rpms” –enable “rhel--extras-rpms” –enable “rhel-ha-for-rhel-*-server-rpms”
RHEL/CentOS 8:
yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm
Note:- EPEL also recommends for RHEL 8, to enable the code ready-builder-for-rhel-8-*-rpms repository since EPEL packages may depend on packages from it. To install it, use the following commands,
ARCH=$( /bin/arch )
subscription-manager repos –enable “codeready-builder-for-rhel-8-${ARCH}-rpms”
Note:- For CentOS 8, EPEL recommends to also enable the PowerTools repository since EPEL packages may depend on packages from it, run the following command to enable power tools,
dnf config-manager –set-enabled PowerTools
Check repository
RHEL/CentOS 6/7
yum repolist
RHEL/CentOS 8