One of the commonest errors CentOS users encounter when using the YUM package manager (for example running the yum update command), especially on a freshly installed system is the “Cannot find a valid baseurl for repo: base/7/x86_64”.
This short article will show how to fix the “cannot find a valid baseurl for repo” error in the CentOS Linux distribution.
The following screenshot shows the above error after running a yum command to search for a package.
yum search redis
The error indicates that YUM is not capable of accessing the base repository that it uses to find package information. In most cases, there are two possible causes of the error: 1) network issues and/or 2) base URL being commented out in the repository configuration file.
You can fix this error in the following ways:
1. Make sure that your system is connected to the Internet. You can try to ping any internet direction, for example, google.com.
ping google.com
The ping result indicates either a DNS problem or no Internet connectivity. In this case, try to edit network interface configuration files. To identify your network interface, run the ip command.
ip add
To edit the configuration for interface enp0s8, open the file /etc/sysconfig/network-scripts/ifcfg-enp0s8 as shown.
vi /etc/sysconfig/network-scripts/ifcfg-enp0s8
If it is a DNS problem, try to add the Nameservers in the configuration file as shown.
DNS1=10.0.2.2 DNS2=8.8.8.8
Then restart the Network Manager service with the systemctl command.
systemctl restart NetworkManager
For more information, read our article: How to Configure Network Static IP Address and Manage Services on RHEL/CentOS 7.0.
After making changes in the network settings, try to run a ping once more.
ping google.com
Now try to run the yum update or any yum command that was showing the above error, once more.
yum search redis
2. If the system is connected to the Internet and DNS is working fine, then there should be an issue with the repo configuration file /etc/yum.repos.d/CentOS-Base.repo.
Open the file using your favorite command-line editor.
vi /etc/yum.repos.d/CentOS-Base.repo
Look for the [base]
section and uncomment the lines starting with baseurl
by removing the leading #
from the baseurl line. Update all instances of http://mirrorlist.centos.org
to http://vault.centos.org
, and also update http://mirror.centos.org
to http://vault.centos.org
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
Save the changes and close the file.
Now try to run the yum command again.
yum update
In this article, we have explained how to fix the “Cannot find a valid baseurl for repo:” error in CentOS 7. We would like to hear from you, and share your experience with us. You can also share solutions you know to fix this issue, via the feedback form below.
Since CentOS 7 has reached its end of life (EOL), the mirrors have been moved to the vault. We need to update the CentOS-Base.repo file located in /etc/yum.repos.d/CentOS-Base.repo.
1. Uncomment the lines starting with baseurl.
2. Replace all instances of
http://mirrorlist.centos.org
withhttp://vault.centos.org
.3. Replace all instances of
http://mirror.centos.org
withhttp://vault.centos.org
.After making these changes, run:
@Reggie,
I’ve updated the instructions regarding the CentOS-Base.repo file due to CentOS 7’s end of life.
This solution did not solve my issue of “Cannot find a valid baseurl for repo:” error in CentOS” any other suggestion.
That helped me. Thank you…
Hello
I fixed this error:
Go to:
Hi
Please full write command line ….
@Arc,
Here’s the step-by-step process for executing the commands you’ve provided:
1. Navigate to the ‘/etc/yum.repos.d‘ directory:
2. Rename all files except ‘CentOS-Base.repo‘ to include the suffix ‘-oldfilename‘:
3. Copy ‘CentOS-Base.repo` to ‘CentOS-Base.repo-‘:
4. Modify ‘CentOS-Base.repo‘ to replace ‘$releasever‘ with `7`:
5. Update the repositories using ‘yum‘:
6. If Linux recovered some files with a
'-'
suffix during step 2, rename them back:7. Modify ‘CentOS-Base.repo‘ again to replace ‘7‘ with ‘$releasever‘:
8. Run ‘yum update‘ again:
This script will execute the steps you’ve outlined, ensuring that the repository files are managed and updated as specified. Make sure to review the changes carefully before executing each command to avoid any unintended consequences.
I have made the changes but I’m unable to save and exit from the editor. How to do it? Can you please explain it?
Reboot your machine that’s the only way to exit vim.
Hit ESC (escape) after that press
:wq
#(WriteQuit) or:q
(Only Quit).IP isn’t installed in the latest centos:7 build, and since yum isn’t working, it’s a little hard to install.
@Adam
You can use this command instead:
I still get :
Hi, It may be caused by your anti-virus. I encounter the same issue on the avast premium. I enabled “Internet Connection Sharing mode” then it worked.
The article was very helpful.
Thanks
A fantastic solution for new learners of Linux.
@R A F I
Thanks for the useful feedback.
Fantastic! It’s solved!
I still get the following error.
http://mirror.centos.org/centos/7/os/x86_64/repodata/repomd.xml: [Errno 14] curl#7 - "Failed connect to mirror.centos.org:80; No route to host"
Hi, The above did not work for me and is still giving the same error.