Bootstrap

CentOS 7 配置yum源

centos 7 配置源

  1. 在CentOS 7上配置软件源,你需要编辑/etc/yum.repos.d/CentOS-Base.repo文件,将其中的镜像地址替换为你所选择的源地址。以下是一个基本的步骤和示例:

备份当前的源文件:

sudo cp /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
  1. 编辑源文件:
sudo vi /etc/yum.repos.d/CentOS-Base.repo
  1. 替换文件内容。你可以选择一个新的镜像站点,将相应的URL替换进去。以下是一个使用阿里云源的示例:
[base]
name=CentOS-$releasever - Base - Aliyun
baseurl=http://mirrors.aliyun.com/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
 
#released updates 
[updates]
name=CentOS-$releasever - Updates - Aliyun
baseurl=http://mirrors.aliyun.com/centos/$releasever/updates/$basearch/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
 
#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras - Aliyun
baseurl=http://mirrors.aliyun.com/centos/$releasever/extras/$basearch/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
 
#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever - Plus - Aliyun
baseurl=http://mirrors.aliyun.com/centos/$releasever/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7

  1. 按Esc键,再英文状态下":wq",保存文件并退出编辑器。
  2. 清除缓存并生成新的缓存:
sudo yum clean all
sudo yum makecache
  1. 完成上述步骤后,CentOS 7系统就会使用新配置的源来进行软件包的安装和更新
;