更改centos ubuntu 服务器的软件源为国内源
更改linux服务器的软件源为国内源
为什么要换源
在使用linux服务器的时候,我们可能会遇到各种各样的问题,其中软件源的问题是最多的,主流的linux系统在安装当中绝大多数都默认配置了国外的源地址,这就造成我们在国内使用的时候不能访问到国外源仓库,又或者说某些IDC运营商提供的服务器有禁止国外访问的防火墙,基于以上的原因我们在使用国内服务器的时候推荐更新自己的源仓库为国内源。
Centos换源
在此豆芽以centos7.6为例详细的教你如何更换系统源仓库为国内源,这里我们使用国内的网易源进行更换,当然其他源比如阿里云,腾讯云,华为云源更换的方法都是大同小异的。
首先登录到服务器,进入到源配置目录 路径为:/etc/yum.repos.d
cd /etc/yum.repos.d
使用命令 ls -a 列出所有文件
[root@s12-196 yum.repos.d]# ls -a
. .. CentOS-Base.repo epel.repo epel-testing.repo
[root@s12-196 yum.repos.d]#
备份默认源配置文件 CentOS-Base.repo
mv CentOS-Base.repo CentOS-Base.repo.bak
该命令的意思为把源配置文件CentOS-Base.repo重命名为CentOS-Base.repo.bak
备份完成以后 下载网易源配置文件
wget http://mirrors.163.com/.help/CentOS7-Base-163.repo
下载完成以后 列出当前目录所有文件
[root@s12-196 yum.repos.d]# ls -a
. CentOS7-Base-163.repo epel.repo
.. CentOS-Base.repo.bak epel-testing.repo
[root@s12-196 yum.repos.d]#
可以看到这里多了一个 CentOS7-Base-163.repo 命令的源配置文件
执行下面的命令 进行配置文件改名 (该命令的意思为修改CentOS7-Base-163.repo为默认源名称)
mv CentOS7-Base-163.repo CentOS-Base.repo
修改成以后 我们在列出所有文件查看一下修改是否生效
[root@s12-196 yum.repos.d]# ls -a
. .. CentOS-Base.repo CentOS-Base.repo.bak epel.repo epel-testing.repo
[root@s12-196 yum.repos.d]#
可以看到CentOS7-Base-163.repo成功更改为 CentOS-Base.repo
下面我们运行下面的命令生成缓存
yum clean all
yum makecache
到此 centos换源的课程结束。
附:网易源centos系统官方换源帮助页面:CentOS镜像使用帮助 (163.com)
附:Centos系统一键换源命令 登录到终端一键执行即可
curl http://cs5.puyun.vip/yum|sh
Ubuntu换源
Ubuntu更换国内源的方法与Centos系统越有差异,Ubuntu源仓库配置文件目录跟Centos不同,Ubuntu源配置文件目录为:/etc/apt/
这里豆芽以ubuntu18.04 lts系统为例 演示如何教你更换ubuntu源为阿里源
进入到源仓库配置目录
cd /etc/apt/
备份默认的源仓库配置文件
mv sources.list sources.list.bak
备份完成以后使用nano编辑器新建阿里源配置文件 当然你也可以使用vi编辑器
nano sources.list
输入下面的配置
deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
保存提交 nano编辑保存文件的方法为:先按ctrl+x 在按y确认保存
保存完成以后 使用下面的命令更新源仓库缓存
apt update
apt upgrade
到此ubuntu18.04更换阿里源的教程结束
附:ubuntu 网易源配置案例
deb http://mirrors.163.com/ubuntu/ bionic main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ bionic-security main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ bionic-updates main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ bionic-backports main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ bionic main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ bionic-security main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ bionic-updates main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ bionic-backports main restricted universe multiverse
附:网易ubuntu换源帮助页面:Ubuntu镜像使用帮助 (163.com)
猜你喜欢
发表评论

暂无评论,你要说点什么吗?