DEV Community

Franz Wong
Franz Wong

Posted on • Edited on

124 1

Fix "Cannot find a valid baseurl for repo" in CentOS

Background

Since CentOS 7 has reached EOL, the mirror is moved to vault. When yum is executed, it will return an error "Cannot find a valid baseurl for repo: base/7/x86_64".

Solution

We need to update CentOS-Base.repo in /etc/yum.repos.d/CentOS-Base.repo.

  1. Uncomment the lines starting with baseurl.

  2. Update all http://mirrorlist.centos.org to http://vault.centos.org.

  3. Update all http://mirror.centos.org to http://vault.centos.org.

  4. We can clear the cache with sudo yum clean all.

Commands:

repo_file=/etc/yum.repos.d/CentOS-Base.repo
cp ${repo_file} ~/CentOS-Base.repo.backup
sudo sed -i s/#baseurl/baseurl/ ${repo_file}
sudo sed -i s/mirrorlist.centos.org/vault.centos.org/ ${repo_file}
sudo sed -i s/mirror.centos.org/vault.centos.org/ ${repo_file}
sudo yum clean all
Enter fullscreen mode Exit fullscreen mode

This is how the file looks like.

# CentOS-Base.repo
#
# The mirror system uses the connecting IP address of the client and the
# update status of each mirror to pick mirrors that are updated to and
# geographically close to the client.  You should use this for CentOS updates
# unless you are manually picking other mirrors.
#
# If the mirrorlist= does not work for you, as a fall back you can try the 
# remarked out baseurl= line instead.
#
#

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

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

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

#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever - Plus
mirrorlist=http://vault.centos.org/?release=$releasever&arch=$basearch&repo=centosplus&infra=$infra
baseurl=http://vault.centos.org/centos/$releasever/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
Enter fullscreen mode Exit fullscreen mode

Postmark Image

Speedy emails, satisfied customers

Are delayed transactional emails costing you user satisfaction? Postmark delivers your emails almost instantly, keeping your customers happy and connected.

Sign up

Top comments (5)

Collapse
 
novria_dedyasihanto_5847 profile image
Novria Dedy Asihanto

thank, this is work !!! thank you very much

Collapse
 
providence_goma_6a0ab1e50 profile image
providence goma

thank you very,

Collapse
 
sven_darwall_b081c9b6b872 profile image
Sven Darwall

Thanks for the help! your tip helped me to be able to run my centOS 7 servers for a while longer

Collapse
 
jay_8eab0849ecdc8b39ee065 profile image
Jay

This worked, thank you so much

Collapse
 
boomerr profile image
LabelEXP

greatgreatgreatful thanks to you!!! it's working!!! god bless you

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

AWS Security LIVE!

Hosted by security experts, AWS Security LIVE! showcases AWS Partners tackling real-world security challenges. Join live and get your security questions answered.

Tune in to the full event

DEV is partnering to bring live events to the community. Join us or dismiss this billboard if you're not interested. ❤️