CentOS7更换yum源和安装EPEL源

centos7:163yum源: 1)备份当前yum源防止出现意外还可以还原回来 cd /etc/yum.repos.d/ cp /CentOS-Base.repo /CentOS-Base-repo.bak 2)使用wget下载163yum源repo文件 wget http://mirrors.163.com/.help/CentOS7-Base-163.repo 3) 清理旧包 yum clean all 4)把下载下来163repo文件设置成为默认源 mv CentOS7-Base-163.repo CentOS-Base.repo 5)生成163yum源缓存并更新yum源 yum makecache yum update 阿里云yum源: 1)备份当前yum源防止出现意外还可以还原回来 cd /etc/yum.repos.d/ cp /CentOS-Base.repo /CentOS-Base-repo.bak 2)使用wget下载阿里yum源repo文件 wget http://mirrors.aliyun.com/repo/Centos-7.repo 3) 清理旧包 yum clean all 4)把下载下来阿里云repo文件设置成为默认源 mv Centos-7.repo CentOS-Base.repo 5)生成阿里云yum源缓存并更新yum源 yum makecache yum update

更换yum源

进入yum配置文件所在文件夹

cd /etc/yum.repos.d/

备份系统自带的yum源配置文件

mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.save

只需添加后缀区分开来就行,旨在若更换yum失败只需恢复自己的备份就行(即去掉后缀)

下载新的源配置文件到该目录下

阿里源的下载方式:

wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo

curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo

网易源的下载方式:

wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.163.com/.help/CentOS7-Base-163.repo

curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.163.com/.help/CentOS7-Base-163.repo

清空系统所有yum源

yum clean all

生成新的yum缓存

yum makecache

至此,yum已更换成功

相关报错

在改动过/etc/yum.repos.d目录下的文件后,再用yum下载软件包的时候,可能会出现以下报错:

Repository base is listed more than once in the configuration
Repository updates is listed more than once in the configuration
Repository extras is listed more than once in the configuration
Repository centosplus is listed more than once in the configuration

分析上面的报错,主要还是软件源文件出现了问题,在进入源的配置文件(/etc/yum.repos.d/)后,使用查看指令,会发现有很多以.repo文件名结尾的:

ll //查看当前目录下的文件详细信息

photo1
从对报错的内容分析来看,应该是存在重复的软件源,所以可以尝试着删除多余的软件源
有如下步骤:
1、在尝试删除之前,先对当前目录下所有文件进行备份

zip centos7-repo.zip /etc/yum.repos.d/*

2、然后执行删除

rm -rf CentOS-CR.repo CentOS-Debuginfo.repo CentOS-fasttrack.repo CentOS-Media.repo CentOS-Sources.repo CentOS-Vault.repo

3、把CentOS7-Base-163.repo中的内容复制进CentOS-Base.repo,即覆盖写入

cp -p CentOS7-Base-163.repo CentOS-Base.repo

4、删除CentOS7-Base-163.repo

rm -rf CentOS7-Base-163.repo

5、重新加载缓存

yum clean all
yum makecache

至此,对该错误的解决已经完成,此时,再用yum指令时就不会出现类似错误

安装EPEL源

安装EPEL源

yum install -y epel-release

安装完成后,在/etc/yum.repos.d/目录下会多出来两个文件,这两个文件就是EPEL源的配置文件,如下:

epel.repo
epel-testing.repo

查看epel.repo文件中的内容就可以发现其中的地址指向的是:https://mirrors.fedoraproject.org/,而epel-testing.repo这个文件中的软件源的地址也是指向的是https://mirrors.fedoraproject.org/
为了加快软件安装速度,我们也可以将其更改为国内的EPEL源。

进入目录

cd /etc/yum.repos.d/

下载阿里云EPEL源

wget http://mirrors.aliyun.com/repo/epel-7.repo

备份官方提供的EPEL源配置文件

cp -p epel.repo epel.repo.bak
cp -p epel-testing.repo epel-testing.repo.bak

下面三步是为了防止安装epel源后出现形如本文中第二版块的yum源配置文件重复而引起的报错:

删除epel-testing.repo文件

rm -rf epel-testing.repo

将epel-7.repo中的内容覆盖写入到原来的epel.repo文件中

cp -p epel-7.repo epel.repo

删除epel-7.repo文件

rm -rf epel-7.repo

重新生成缓存

yum clean all
yum makecache

至此,EPEL源安装及更换站点完成

THE END
分享
二维码
< <上一篇
下一篇>>