How to Fix “Cannot find a valid baseurl for repo” in CentOS

One of the commonest errors CentOS users encounter when using YUM package manager (for example running yum update command), especially on a freshly installed system is the “Cannot find a valid baseurl for repo: base/7/x86_64”.

In this short article, we will show how to fix “cannot find a valid baseurl for repo” error in CentOS Linux distribution.

The following screenshot shows the above error after running a yum command to search for a package.

# yum search redis
Cannot Find a Valid Baseurl for Repo Error
Cannot Find a Valid Baseurl for Repo Error

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
Ping a Host
Ping a Host

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
Identify Network Interfaces
Identify Network Interfaces

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
Ping a Host Again
Ping a Host Again

Now run try to run the yum update or the any yum command that was showing the above error, once more.

# yum search redis
Search for a Package
Search for a Package

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, try uncommenting the baseurl by removing the leading # on the baseurl line as shown in the following screenshot.

Edit Yum Repo File
Edit Yum Repo File

Save the changes and close the file. Now try to run 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, share your experience with us. You can also share solutions you know to fix this issue, via the feedback form below.

Aaron Kili
Aaron Kili is a Linux and F.O.S.S enthusiast, an upcoming Linux SysAdmin, web developer, and currently a content creator for TecMint who loves working with computers and strongly believes in sharing knowledge.

Each tutorial at TecMint is created by a team of experienced Linux system administrators so that it meets our high-quality standards.

Join the TecMint Weekly Newsletter (More Than 156,129 Linux Enthusiasts Have Subscribed)
Was this article helpful? Please add a comment or buy me a coffee to show your appreciation.

19 thoughts on “How to Fix “Cannot find a valid baseurl for repo” in CentOS”

  1. This solution did not solve my issue of “Cannot find a valid baseurl for repo:” error in CentOS” any other suggestion.

    Reply
  2. Hello

    I fixed this error:

    Go to:

    1. /etc/yum.repos.d
    2. rename all files, except(CentOS-Base.repo ) to “old filename-“
    3. copy CentOS-Base.repo to CentOS-Base.repo-
    4. In CentOS-Base.repo I replace $releasever to 7
    5. run: yum update
    6. In /etc/yum.repos.d Linux ercovered some file with “-” siffix at step2, I rename back all files which not recovered
    7. In CentOS-Base.repo I replace 7 to $releasever
    8. again run: yum update
    Reply
      • @Arc,

        Here’s the step-by-step process for executing the commands you’ve provided:

        1. Navigate to the ‘/etc/yum.repos.d‘ directory:

        cd /etc/yum.repos.d
        

        2. Rename all files except ‘CentOS-Base.repo‘ to include the suffix ‘-oldfilename‘:

        for file in *; do
               if [ "$file" != "CentOS-Base.repo" ]; then
                   mv "$file" "${file}-oldfilename"
               fi
           done
        

        3. Copy ‘CentOS-Base.repo` to ‘CentOS-Base.repo-‘:

        cp CentOS-Base.repo CentOS-Base.repo-
        

        4. Modify ‘CentOS-Base.repo‘ to replace ‘$releasever‘ with `7`:

        sed -i 's/$releasever/7/g' CentOS-Base.repo
        

        5. Update the repositories using ‘yum‘:

        yum update
        

        6. If Linux recovered some files with a '-' suffix during step 2, rename them back:

           for file in *; do
               if [[ "$file" == *-oldfilename ]]; then
                   new_file=$(echo "$file" | sed 's/-oldfilename//')
                   mv "$file" "$new_file"
               fi
           done
        

        7. Modify ‘CentOS-Base.repo‘ again to replace ‘7‘ with ‘$releasever‘:

        sed -i 's/7/$releasever/g' CentOS-Base.repo
        

        8. Run ‘yum update‘ again:

        yum update
        

        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.

        Reply
  3. I still get :

    [root@box ~]# yum update
    Loaded plugins: fastestmirror
    Determining fastest mirrors
    YumRepo Error: All mirror URLs are not using ftp, http[s] or file.
     Eg. Invalid release/repo/arch combination/
    removing mirrorlist with no valid mirrors: /var/cache/yum/addons/mirrorlist.txt
    Error: Cannot find a valid baseurl for repo: addons
    
    Reply
  4. 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.

    Reply
  5. 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"

    Reply

Got something to say? Join the discussion.

Thank you for taking the time to share your thoughts with us. We appreciate your decision to leave a comment and value your contribution to the discussion. It's important to note that we moderate all comments in accordance with our comment policy to ensure a respectful and constructive conversation.

Rest assured that your email address will remain private and will not be published or shared with anyone. We prioritize the privacy and security of our users.