19

I have a situation where the stock repo files that should exist in /etc/yum.repos.d/ (like centos-base.repo) are not present. I need to get them installed. I am sure this is simple, but after hours of searching, it seems I am not googling it correctly.

Basically I have a server with custom repos that are useless to me. I need epel, and epel needs centos-base.repo. I also need postgres repo.

  • 1
    or u can install OS on a virtual machine and later copy the default file located in yum.repos.d directory – OmiPenguin Oct 23 '12 at 12:33
16

Create a file called Centos-Base.repo in the following directory /etc/yum.repos.d

vi /etc/yum.repos.d/Centos-Base.repo

Put the following info inside of the file:

[base]
name=CentOS-$releasever - Base
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=
$basearch&repo=os
#baseurl=http://mirror.centos.org/centos/$releasever/os/$basearch/
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-5
priority=1

#released updates 
[updates]
name=CentOS-$releasever - Updates
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=
$basearch&repo=updates
#baseurl=http://mirror.centos.org/centos/$releasever/updates/$basearch/
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-5
priority=1

#packages used/produced in the build but not released
[addons]
name=CentOS-$releasever - Addons
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=
$basearch&repo=addons
#baseurl=http://mirror.centos.org/centos/$releasever/addons/$basearch/
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-5
priority=1

#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=
$basearch&repo=extras
#baseurl=http://mirror.centos.org/centos/$releasever/extras/$basearch/
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-5
priority=1

#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever - Plus
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=
$basearch&repo=centosplus
#baseurl=http://mirror.centos.org/centos/$releasever/centosplus/$basearch/
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-5
priority=2

#contrib - packages by Centos Users
[contrib]
name=CentOS-$releasever - Contrib
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=
$basearch&repo=contrib
#baseurl=http://mirror.centos.org/centos/$releasever/contrib/$basearch/
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-5
priority=2

Save it and run.

yum clean all 

Then run.

yum repolist

If you're copying this into putty via vi then make sure you double check line breaks. I had to fix some editing that happened during the copy-paste.

  • 5
    Instead of pasting into an editor like vi or vim, just use cat > filename and press ctrl-d after pasting. Also, vim has a mode designed for receiving data from the clipboard, which will disable auto formatting, etc. Just use ":set paste" before entering insert mode. But I still prefer the cat method, it's simpler. – Watcom Jan 15 '14 at 19:20
  • 2
    Why does this have GPG files for CEntOS-5, e.g. gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-5 ? – Nathan Basanese Aug 19 '15 at 21:55
  • 3
    It doesn't work on CentOS-7 – Alex Jolig Jun 14 '17 at 7:49
  • For the FYI of posterity who now come to this question: those URLs are no longer valid for CentOS 5. You can use this instead: archive.kernel.org/centos-vault/5.7 (adjusting for your version of course) . I found that URL at the bottom of this page: vault.centos.org/centos – Todd Walton Apr 29 at 13:01
10

You could manually reinstall the centos-release-rpm using:

rpm -ivh --replacepkgs --replacefiles centos-release*.rpm
  • 3
    This worked, but it needed modification. The first step is to see if the centos-release package is installed, by typing rpm -q centos-release. If it's not installed, then the --replacepkgs --replacefiles part of the command should be omitted. In my case the whole thing had been deinstalled, so I used: rpm -Uvh centos-release.*.rpm – Jim Oct 24 '12 at 1:29
  • @Jim that must have been a brutal removal of that rpm - without dependency-check. I checked with yum remove centos-release - that should normally deinstall the whole system. – Nils Oct 24 '12 at 13:58
3

For me problem solved by clean all repositories and adding new ones from here considering my CentOS version:

# yum clean all

# rpm -Uvh http://dl.fedoraproject.org/pub/epel/7/x86_64/e/epel-release-7-9.noarch.rpm

# rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-7.rpm

# rpm -Uvh http://dl.atrpms.net/all/atrpms-repo-7-7.el7.x86_64.rpm

# rpm -Uvh http://repo.webtatic.com/yum/el7/webtatic-release.rpm
  • The first URL is no longer valid. Haven't checked the others. – theMayer Feb 17 '18 at 22:14

protected by Anthon Sep 19 '17 at 10:13

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged or ask your own question.