以Ubuntu16.04为例
操作步骤
1 备份原来的源文件
sudo cp /etc/apt/sources.list /etc/apt/sources.list.bcakup
2 编辑源文件
编辑器打开源文件
sudo vi /etc/apt/sources.list
清空后输入以下内容
# 阿里云源
deb [http://mirrors.aliyun.com/ubuntu/](http://mirrors.aliyun.com/ubuntu/) xenial main restricted universe multiverse
deb [http://mirrors.aliyun.com/ubuntu/](http://mirrors.aliyun.com/ubuntu/) xenial-security main restricted universe multiverse
deb [http://mirrors.aliyun.com/ubuntu/](http://mirrors.aliyun.com/ubuntu/) xenial-updates main restricted universe multiverse
deb [http://mirrors.aliyun.com/ubuntu/](http://mirrors.aliyun.com/ubuntu/) xenial-backports main restricted universe multiverse
##測試版源
deb [http://mirrors.aliyun.com/ubuntu/](http://mirrors.aliyun.com/ubuntu/) xenial-proposed main restricted universe multiverse
# 源碼
deb-src [http://mirrors.aliyun.com/ubuntu/](http://mirrors.aliyun.com/ubuntu/) xenial main restricted universe multiverse
deb-src [http://mirrors.aliyun.com/ubuntu/](http://mirrors.aliyun.com/ubuntu/) xenial-security main restricted universe multiverse
deb-src [http://mirrors.aliyun.com/ubuntu/](http://mirrors.aliyun.com/ubuntu/) xenial-updates main restricted universe multiverse
deb-src [http://mirrors.aliyun.com/ubuntu/](http://mirrors.aliyun.com/ubuntu/) xenial-backports main restricted universe multiverse
##測試版源
deb-src [http://mirrors.aliyun.com/ubuntu/](http://mirrors.aliyun.com/ubuntu/) xenial-proposed main restricted universe multiverse
3 执行更新
保存退出后执行以下命令
sudo apt update
其他Ubuntu版本
1 查看版本号
执行lsb_release -a
查看codename,对应的就是相应的版本号,不同版本号需要将以上文本内容“xenial”对应修改
例如,版本号为“bionic”的版本,文本内容为:
# 阿里云源
deb [http://mirrors.aliyun.com/ubuntu/](http://mirrors.aliyun.com/ubuntu/) bionic main restricted universe multiverse
deb [http://mirrors.aliyun.com/ubuntu/](http://mirrors.aliyun.com/ubuntu/) bionic-security main restricted universe multiverse
deb [http://mirrors.aliyun.com/ubuntu/](http://mirrors.aliyun.com/ubuntu/) bionic-updates main restricted universe multiverse
deb [http://mirrors.aliyun.com/ubuntu/](http://mirrors.aliyun.com/ubuntu/) bionic-backports main restricted universe multiverse
##測試版源
deb [http://mirrors.aliyun.com/ubuntu/](http://mirrors.aliyun.com/ubuntu/) bionic-proposed main restricted universe multiverse
# 源碼
deb-src [http://mirrors.aliyun.com/ubuntu/](http://mirrors.aliyun.com/ubuntu/) bionic main restricted universe multiverse
deb-src [http://mirrors.aliyun.com/ubuntu/](http://mirrors.aliyun.com/ubuntu/) bionic-security main restricted universe multiverse
deb-src [http://mirrors.aliyun.com/ubuntu/](http://mirrors.aliyun.com/ubuntu/) bionic-updates main restricted universe multiverse
deb-src [http://mirrors.aliyun.com/ubuntu/](http://mirrors.aliyun.com/ubuntu/) bionic-backports main restricted universe multiverse
##測試版源
deb-src [http://mirrors.aliyun.com/ubuntu/](http://mirrors.aliyun.com/ubuntu/) bionic-proposed main restricted universe multiverse
更换其他源
除了阿里云国内的源,可以打开https://wiki.ubuntu.org.cn/%E6%A8%A1%E6%9D%BF:18.04source#.E6.9C.8D.E5.8B.99.E5.99.A8.E5.88.97.E8.A1.A8
进行查看,可将 http://mirrors.aliyun.com/ubuntu/换为网址中任意服务器