'Install Python 3 on Centos 8 returns "Failed to synchronize cache for repo 'BaseOS'"

I am using CentOS 8. I'm trying to install Python 3. Command: sudo dnf install python3. Error:

Failed to synchronize cache for repo 'BaseOS'

How can I fix this?



Solution 1:[1]

Centos did something funny with the value of $releasever in that they were using the full version 8.0.1905 instead of just 8. When the new version 8.1.1911 was released they archived the old version. If you do in install of old media or use an old vagrant box this may cause the following issue:

[vagrant@localhost ~]$ sudo dnf upgrade
CentOS-8.0 - AppStream                                                                                                                                                                                        1.6 kB/s |  38  B     00:00    
CentOS-8.0 - Base                                                                                                                                                                                             748  B/s |  38  B     00:00    
CentOS-8.0 - Extras                                                                                                                                                                                           126  B/s |  38  B     00:00    
Extra Packages for Enterprise Linux Modular 8.0 - x86_64                                                                                                                                                       53 kB/s |  63 kB     00:01    
Extra Packages for Enterprise Linux 8.0 - x86_64                                                                                                                                                               80 kB/s |  63 kB     00:00    
Failed to synchronize cache for repo 'AppStream', ignoring this repo.
Failed to synchronize cache for repo 'BaseOS', ignoring this repo.
Failed to synchronize cache for repo 'extras', ignoring this repo.
Failed to synchronize cache for repo 'epel-modular', ignoring this repo.
Failed to synchronize cache for repo 'epel', ignoring this repo.
Dependencies resolved.
Nothing to do.
Complete!

The fix for this is to specify the Centos version on the dnf command line using the --releasever option like this:

[vagrant@localhost ~]$ sudo dnf upgrade --releasever=8
CentOS-8 - AppStream                                                                                                                                                                                          164 kB/s | 7.0 MB     00:43    
CentOS-8 - Base                                                                                                                                                                                               313 kB/s | 2.2 MB     00:07    
CentOS-8 - Extras                                                                                                                                                                                             5.1 kB/s | 5.5 kB     00:01    
Extra Packages for Enterprise Linux Modular 8 - x86_64                                                                                                                                                         63 kB/s | 116 kB     00:01    
Extra Packages for Enterprise Linux 8 - x86_64                                                                                                                                                                5.9 MB/s | 6.5 MB     00:01    
Dependencies resolved.

Solution 2:[2]

Change the baseurl from mirror.centos.org to vault.centos.org in the appropriate repo file here:

/etc/yum.repos.d/

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Tim Hughes
Solution 2 MacGyver