Ubuntu18.04下更改apt源为阿里云源

服务器版本:阿里云轻服务器Ubuntu 18.04

问题:

apt安装软件时,提示:Failed to fetch http://mirrors.cloud.aliyuncs.com/

执行apt-get update命令更新源提示:

1
2
3
4
5
6
7
8
9
10
11
12
13
Err:1 http://mirrors.cloud.aliyuncs.com/ubuntu bionic InRelease
  Could not resolve 'mirrors.cloud.aliyuncs.com'
Err:2 http://mirrors.cloud.aliyuncs.com/ubuntu bionic-updates InRelease
  Could not resolve 'mirrors.cloud.aliyuncs.com'
Err:3 http://mirrors.cloud.aliyuncs.com/ubuntu bionic-security InRelease
  Could not resolve 'mirrors.cloud.aliyuncs.com'
Hit:4 http://ppa.launchpad.net/nginx/stable/ubuntu bionic InRelease
Hit:5 http://ppa.launchpad.net/ondrej/php/ubuntu bionic InRelease
Reading package lists... Done
W: Failed to fetch http://mirrors.cloud.aliyuncs.com/ubuntu/dists/bionic/InRelease  Could not resolve 'mirrors.cloud.aliyuncs.com'
W: Failed to fetch http://mirrors.cloud.aliyuncs.com/ubuntu/dists/bionic-updates/InRelease  Could not resolve 'mirrors.cloud.aliyuncs.com'
W: Failed to fetch http://mirrors.cloud.aliyuncs.com/ubuntu/dists/bionic-security/InRelease  Could not resolve 'mirrors.cloud.aliyuncs.com'
W: Some index files failed to download. They have been ignored, or old ones used instead.

解决方案:

1.备份源列表文件:

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

2.编辑源列表文件:

1
2
3
4
5
6
7
8
9
10
11
12
vi /etc/apt/sources.list
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-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-backports 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
:wq!

3.执行更新命令:

1
apt-get update

4.可以正常安装软件包了:

1
apt install traceroute

5. END.

上一篇: