海外CN2直连服务器
腾讯云优惠|主机测评网!

centos/ubuntu系统服务器切换国内软件/镜像源教程

文章目录[隐藏]

在日常的Linux系统服务器运维中,我们通常会碰到许多问题。而软件源的问题也是遇到的非常多的,我们购买vps后通常预装的是纯净版Linux系统,此时大多数是国外源(相信大家在安装的时候都被下载速度困扰过),国内用户访问不到国外的软件源仓库,基于以上原因小编推荐购买vps后更换源仓库为国内源。

在此雪花测评给大家带来centosubuntu换源的教程,希望可以帮助大家解决运维中的难题!

Centos系统换源

在此雪花博客以centos7.6为例详细的教你如何更换系统源仓库为国内源,这里我们使用国内的网易源进行更换,当然其他源比如阿里云,腾讯云,华为云源更换的方法都是大同小异的。

首先登录到服务器,进入到源配置目录 路径为:/etc/yum.repos.d,命令如下:

cd /etc/yum.repos.d

使用命令 ls 列出所有文件

[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

可以看到这里多了一个 CentOS7-Base-163.repo 命令的源配置文件

执行下面的命令 进行配置文件改名 (该命令的意思为修改CentOS7-Base-163.repo为默认源名称)

mv CentOS7-Base-163.repo  CentOS-Base.repo

修改成以后 我们在列出所有文件查看一下修改是否生效,执行:ls -a

[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系统一键换源命令 登录到终端一键执行即可

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

centos系统切换网易源 | Ubuntu切换网易云镜像教程

其他系统大同小异,直接切换源地址就可以!

好啦,上面是小编分享的Linux切换镜像源方法教程,如果对您有用,别忘了收藏本站哦~

赞(1)
未经允许不得转载:雪花测评 » centos/ubuntu系统服务器切换国内软件/镜像源教程
分享到: 更多 (0)

国内建站推荐腾讯云轻量级应用服务器,开箱即用。最新活动:点我进入