前些天华为云活动256抢了一个3年1核2G 100%性能的服务器,今天抽时间配置一下,发现使用apt-get安装东西的时候总是会失败,提示需要apt-get update,但是执行后又会报错“W: Some index files failed to download. They have been ignored, or old ones used instead.”,想了想应该是源的问题,于是查了一下Ubuntu更改下载源的方法,记录一下。

首先系统自带的apt-get源配置文件在这里

1
/etc/apt/sources.list

以防万一备份一下

1
cp /etc/apt/sources.list /etc/apt/sources.list.bak

查看自己的系统Codename

1
2
lsb_release -c
> Codename: bionic
系统 对应Codename
12.04 precise
14.04 trusty
15.04 vivid
15.10 wily
16.04 xenial
18.04 bionic
20.04 focal

根据自己的Codename配置对应的源地址,阿里云镜像站

最后编辑/etc/apt/sources.list源文件,改为以下内容

1
2
3
4
5
6
7
8
9
10
deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src 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-backports main restricted universe multiverse

或者清华大学源

重新试一下,OK

1
apt-get update

最后自发的打个广告:华为云活动不得不说优惠力度挺大的,需要的可以先注册个账号占个坑。