1. 程式人生 > >Linux 更換清華yum源

Linux 更換清華yum源

解決yum install 報錯問題

在虛擬機器上安裝了Centos 6.8 mininal版本 由於網速太慢,用yum安裝老是報超時錯誤 於是打算將yum源換成國內源,安裝網上的教程 安裝過阿里雲和163源 老是報下面的錯誤

Loaded plugins: fastestmirror
Determining fastest mirrors
http://mirrors.163.com/centos/6/os/x86_64/repodata/repomd.xml: [Errno 14] PYCURL ERROR 56 - "Failure when receiving data from the peer"
Trying other mirror. Error: Cannot retrieve repository metadata (repomd.xml) for repository: base. Please verify its path and try again

搜尋了各種辦法都不行,正打算換回原來的備份時又不小心把備份給刪掉了,於是打算重新下載一個CentOS-Base.repo 檔案,這次隨意找了個清華的源,結果卻成功了。我也不清楚什麼原因,希望有知情人可以告知,謝謝了。

更換yum源

牢騷發完了,下面開始正題

首先備份原始檔 CentOS-Base.repo

sudo mv /etc/yum.repos
.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak

將新的原始檔上傳到/etc/yum.repos.d 目錄或在改目錄下新建一個檔案 命名為 CentOS-Base.repo
內容為
注意 這是 Centos 6的 其他版本 請點開連結去複製 清華大學映象站

# 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 baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/os/$basearch/ #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6 #released updates [updates] name=CentOS-$releasever - Updates baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/updates/$basearch/ #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6 #additional packages that may be useful [extras] name=CentOS-$releasever - Extras baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/extras/$basearch/ #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6 #additional packages that extend functionality of existing packages [centosplus] name=CentOS-$releasever - Plus baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/centosplus/$basearch/ #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus gpgcheck=1 enabled=0 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6 #contrib - packages by Centos Users [contrib] name=CentOS-$releasever - Contrib baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/contrib/$basearch/ #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=contrib gpgcheck=1 enabled=0 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6

執行命令

yum clean all
yum makecache

OK yum源更換完畢了