以下提供设置阿里源的方法,其他源也可以如法炮制:
- 首先查看自己的ubuntu系统的codename,这一步很重要,直接导致你更新的源是否对你的系统起效果,查看方法:在终端输入命令,
lsb_release -a
如,我的系统显示:
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 17.10
Release: 17.10
Codename: artful
显示了一些ubuntu的版本信息,需要得到的是Codename,比如,我这里是artful
2.确认阿里源支持:
登陆以下网页:http://mirrors.aliyun.com/ubuntu/dists/
该网页显示了阿里云支持的ubuntu系统下各个Codename版本,确保自己的Codename在该网页中存在(一般都会有的)
3.备份系统源:切换路径cd /etc/apt
复制原文件备份 sudo mv sources.list sources.list_bak
4.添加新的源文件:sudo vi sources.list
并添加以下内容:注意,每一行的artful应该用第一步查看得到的Codename来代替
deb http://mirrors.aliyun.com/ubuntu/ artful main multiverse restricted universe
deb http://mirrors.aliyun.com/ubuntu/ artful-backports main multiverse restricted universe
deb http://mirrors.aliyun.com/ubuntu/ artful-proposed main multiverse restricted universe
deb http://mirrors.aliyun.com/ubuntu/ artful-security main multiverse restricted universe
deb http://mirrors.aliyun.com/ubuntu/ artful-updates main multiverse restricted universe
deb-src http://mirrors.aliyun.com/ubuntu/ artful main multiverse restricted universe
deb-src http://mirrors.aliyun.com/ubuntu/ artful-backports main multiverse restricted universe
deb-src http://mirrors.aliyun.com/ubuntu/ artful-proposed main multiverse restricted universe
deb-src http://mirrors.aliyun.com/ubuntu/ artful-security main multiverse restricted universe
deb-src http://mirrors.aliyun.com/ubuntu/ artful-updates main multiverse restricted universe
5.保存并且sudo apt-get update,更新成功
6.如果嫌弃上面步骤繁琐的话,可以直接执行以下提供配置脚本:
Codename=$( (lsb_release -a)|awk '{print $2}'|tail -n 1 )
echo "\
deb http://mirrors.aliyun.com/ubuntu/ $Codename main multiverse restricted universe
deb http://mirrors.aliyun.com/ubuntu/ $Codename-backports main multiverse restricted universe
deb http://mirrors.aliyun.com/ubuntu/ $Codename-proposed main multiverse restricted universe
deb http://mirrors.aliyun.com/ubuntu/ $Codename-security main multiverse restricted universe
deb http://mirrors.aliyun.com/ubuntu/ $Codename-updates main multiverse restricted universe
deb-src http://mirrors.aliyun.com/ubuntu/ $Codename main multiverse restricted universe
deb-src http://mirrors.aliyun.com/ubuntu/ $Codename-backports main multiverse restricted universe
deb-src http://mirrors.aliyun.com/ubuntu/ $Codename-proposed main multiverse restricted universe
deb-src http://mirrors.aliyun.com/ubuntu/ $Codename-security main multiverse restricted universe
deb-src http://mirrors.aliyun.com/ubuntu/ $Codename-updates main multiverse restricted universe ">sources.list
apt-get update
sudo运行该脚本即可(注意运行之前最好备份之前的sources.list)