更改CentOS7 yum源

方法一:更改相关文件

(1)先将yum源文件备份

cp CentOS-Base.repo CentOs-Base.repo.backup

(2)转到yum源目录,便于下一步操作

cd /etc/yum.repos.d

(3)更改配置文件

vi CentOS-Base.repo	

将文件中的内容改为下面的代码

# 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 - 163.com
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os
baseurl=http://mirrors.163.com/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-7

#released updates
[updates]
name=CentOS-$releasever - Updates - 163.com
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates
baseurl=http://mirrors.163.com/centos/$releasever/updates/$basearch/
gpgcheck=1
gpgkey=http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-7

#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras - 163.com
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras
baseurl=http://mirrors.163.com/centos/$releasever/extras/$basearch/
gpgcheck=1
gpgkey=http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-7

#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever - Plus - 163.com
baseurl=http://mirrors.163.com/centos/$releasever/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-7

方法二:将国外镜像源改为国内的

(1)首先还是将文件备份

cp CentOS-Base.repo CentOs-Base.repo.backup

(2)转到相关目录

cd /etc/yum.repos.d

(3) 更换yum源        //我这里是将镜像源切换成了阿里云镜像源

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

相关镜像源还有

阿里云开源镜像站:阿里巴巴开源镜像站-OPSX镜像站-阿里云开发者社区阿里巴巴开源镜像站,免费提供Linux镜像下载服务,拥有Ubuntu、CentOS、Deepin、MongoDB、Apache、Maven、Composer等多种开源软件镜像源,此外还提供域名解析DNS、网络授时NTP等服务,致力于为互联网用户提供全面,高效和稳定的基础服务。icon-default.png?t=O83Ahttps://mirrors.aliyun.com/

网易开源镜像站:欢迎访问网易开源镜像站icon-default.png?t=O83Ahttps://mirrors.163.com/

中科大开源镜像站:USTC Open Source Software Mirroricon-default.png?t=O83Ahttps://mirrors.ustc.edu.cn/

清华开源镜像站:清华大学开源软件镜像站 | Tsinghua Open Source Mirror清华大学开源软件镜像站,致力于为国内和校内用户提供高质量的开源软件镜像、Linux 镜像源服务,帮助用户更方便地获取开源软件。本镜像站由清华大学 TUNA 协会负责运行维护。icon-default.png?t=O83Ahttps://mirrors.tuna.tsinghua.edu.cn/

(4)清除旧的yum缓存

yum clean all

(5)生成新的yum缓存

yum makecache

(6)更新软件包

yum update -y

关于yum的一些指令(以下载nginx为例)

yum install epel-release -y    #yum安装拓展yum仓库

yum install nginx -y    #下载

yum remove ngnix -y    #卸载

yum repolist    #查看rpm的数量

你可能感兴趣的:(linux,centos)