33

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.

muru
  • 69,900
  • 13
  • 192
  • 292
Jim
  • 331
  • 1
  • 3
  • 3
  • 2
    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

3 Answers3

25

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.

Anthon
  • 78,313
  • 42
  • 165
  • 222
midnightsteel
  • 822
  • 6
  • 10
  • 7
    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 – Ghasem Jun 14 '17 at 07:49
  • 1
    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: http://archive.kernel.org/centos-vault/5.7/ (adjusting for your version of course) . I found that URL at the bottom of this page: http://vault.centos.org/centos/ – Todd Walton Apr 29 '19 at 13:01
11

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

rpm -ivh --replacepkgs --replacefiles centos-release*.rpm
slm
  • 363,520
  • 117
  • 767
  • 871
Nils
  • 18,202
  • 11
  • 46
  • 82
  • 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 01: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
  • This doesnt work. rpm -ivh --replacepkgs --replacefiles centos-release*.rpm – avia May 15 '21 at 23:03
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
Ghasem
  • 2,289
  • 3
  • 15
  • 19