fix bug yum install Centos 7, 8 – change repository link

If you’re using CentOS 7, you might encounter issues when updating packages from the default repositories since CentOS has stopped supporting older versions. To continue using CentOS 7, you can modify the repo file to switch from mirror.centos.org to vault.centos.org, which hosts archived versions of CentOS. Below is a detailed guide on how to do this.

Could not retrieve mirrorlist http://mirrorlist.centos.org/?release=7&arch=x86_64&repo=os&infra=genclo error was<br />14: curl#6 - "Could not resolve host: mirrorlist.centos.org; Unknown error"

1. Modify the CentOS-Base.repo File

Step 1: Open the CentOS-Base.repo Configuration File

This file contains information about the CentOS repositories that the system uses for commands like yum update or yum install. You can open it with the following command:

bash
vi /etc/yum.repos.d/CentOS-Base.repo

Step 2: Replace mirror.centos.org with vault.centos.org

Once the file is open, find the line containing mirrorlist and replace it with the baseurl pointing to vault.centos.org. Specifically, replace this line:

mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras&infra=$infra

With this line:

baseurl=http://vault.centos.org/7.9.2009/os/$basearch/

You can manually edit the lines or use the following sed command to automate the replacement:

sed -i s/mirror.centos.org/vault.centos.org/g /etc/yum.repos.d/*.repo 
sed -i s/^#.baseurl=http/baseurl=http/g /etc/yum.repos.d/*.repo 
sed -i s/^mirrorlist=http/#mirrorlist=http/g /etc/yum.repos.d/*.repo

 

Step 3: Verify the Repo File

After making the changes, review the contents of the CentOS-Base.repo file to ensure that all paths have been replaced with vault.centos.org. The correct configuration should look like this:

[base]
name=CentOS-7 - Base
baseurl=http://vault.centos.org/7.9.2009/os/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

[updates]
name=CentOS-7 - Updates
baseurl=http://vault.centos.org/7.9.2009/updates/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

[extras]
name=CentOS-7 - Extras
baseurl=http://vault.centos.org/7.9.2009/extras/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

2. Update the System

After configuring the repository file, you can use the following command to install essential packages:

yum install -y epel-release yum update -y

 

If successful, the system will download and install updates from vault.centos.org.

3. Install Basic Packages

Next, you can install essential tools on your system with the following command:

yum install -y htop bash-completion net-tools chrony keepalived wget

 

No episodes found.Posted in Centos 7, Centos 8, Linux

Leave a Reply

Your email address will not be published. Required fields are marked *