Skip to content

Instantly share code, notes, and snippets.

@RulerOf
Last active October 29, 2022 17:17
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save RulerOf/2bc34db224ccf8606e41b16c315d0bb6 to your computer and use it in GitHub Desktop.
Save RulerOf/2bc34db224ccf8606e41b16c315d0bb6 to your computer and use it in GitHub Desktop.
Adding Centos Extras repo to Oracle Enterprise Linux 7

Adding CentOS Extras to Oracle Enterprise Linux

If you want to install a package like Docker Community Edition on OEL, you'll have to add the CentOS Extras repo, which as of release 7 is built-in to CentOS and not added on later like EPEL is. As a result, instructions for adding it to EL7 are hard to find. This should work for any build of Enterprise Linux that does not already include the CentOS Extras repo. I have absolutely no idea if it's apporpriate to use this repo on a build of Linux other than CentOS, but it should be.

This was tested on Oracle Enterprise Linux 7, but should be copy-pastable on any version or EL build assuming things don't change too much.

Download the CentOS GPG Key

# Get OS Release number
OS_RELEASE=$(rpm -q --qf "%{VERSION}" $(rpm -q --whatprovides redhat-release))
OS_RELEASE_MAJOR=$(echo $OS_RELEASE | cut -d. -f1)
# Download the GPG key and save locally
curl -s https://www.centos.org/keys/RPM-GPG-KEY-CentOS-$OS_RELEASE_MAJOR | sudo tee /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-$OS_RELEASE_MAJOR

Create the repo file

A bash implementation of this stackoverflow answer:

# Get OS Release number
OS_RELEASE=$(rpm -q --qf "%{VERSION}" $(rpm -q --whatprovides redhat-release))
OS_RELEASE_MAJOR=$(echo $OS_RELEASE | cut -d. -f1)
# Create the repo file
cat << EOF | sudo tee /etc/yum.repos.d/centos-extras.repo
#additional packages that may be useful
[extras]
name=CentOS-$OS_RELEASE_MAJOR - Extras
mirrorlist=http://mirrorlist.centos.org/?release=$OS_RELEASE_MAJOR&arch=\$basearch&repo=extras
#baseurl=http://mirror.centos.org/centos/$OS_RELEASE_MAJOR/extras/\$basearch/
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-$OS_RELEASE_MAJOR
priority=1
EOF

Build the repo cache

sudo yum -q makecache -y --disablerepo='*' --enablerepo='extras'
@JoaoPedroAlex
Copy link

Something is wrong with the previous instructions.
The result in the file was

#additional packages that may be useful
[extras]
name=CentOS-9 - Extras
mirrorlist=http://mirrorlist.centos.org/?release=9&arch=$basearch&repo=extras
#baseurl=http://mirror.centos.org/centos/9/extras/$basearch/
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-9
priority=1
[root@localhost ~]# yum -q makecache -y --disablerepo='*' --enablerepo='extras'
Erro: Failed to download metadata for repo 'extras': Cannot prepare internal mirrorlist: No URLs in mirrorlist

@RulerOf
Copy link
Author

RulerOf commented Oct 29, 2022

@JoaoPedroAlex I never tested on later than OEL7. Still have yet to upgrade the server I wrote this with.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment