在Ubuntu16.04中安裝LAMP時,使用了
sudo apt-get update
無法更新,報了一大堆錯誤
Err:1 http://security.ubuntu.com/ubuntu xenial-security InRelease
Temporary failure resolving 'security.ubuntu.com'
Err:2 http://mirrors.digitalocean.com/ubuntu xenial InRelease
Temporary failure resolving 'mirrors.digitalocean.com'
Err:3 http://mirrors.digitalocean.com/ubuntu xenial-updates InRelease
Temporary failure resolving 'mirrors.digitalocean.com'
Err:4 http://mirrors.digitalocean.com/ubuntu xenial-backports InRelease
Temporary failure resolving 'mirrors.digitalocean.com'
Reading package lists... Done
W: Failed to fetch http://mirrors.digitalocean.com/ubuntu/dists/xenial/InRelease Temporary failure resolving 'mirrors.digitalocean.com'
W: Failed to fetch http://mirrors.digitalocean.com/ubuntu/dists/xenial-updates/InRelease Temporary failure resolving 'mirrors.digitalocean.com'
W: Failed to fetch http://mirrors.digitalocean.com/ubuntu/dists/xenial-backports/InRelease Temporary failure resolving 'mirrors.digitalocean.com'
W: Failed to fetch http://security.ubuntu.com/ubuntu/dists/xenial-security/InRelease Temporary failure resolving 'security.ubuntu.com'
W: Some index files failed to download. They have been ignored, or old ones used instead.
一些索引文件沒有下載,源可能有點問題。查找解決辦法,大家給出的意見是修改/etc/apt/source.list文件,將源改成163的或者阿里的,在source.list中添加幾行
deb http://mirrors.aliyun.com/ubuntu/ xenial main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse
ftp修改完後,還是無法更新。
最終解決辦法:
修改DNS
sudo vi /etc/resolvconf/resolv.conf.d/base
在裏面插入:
nameserver 8.8.8.8
nameserver 8.8.4.4
修改好,按Esc,並輸入:wq!來強制保存並退出vi
執行
sudo resolvconf -u
檢查/etc/resolv.conf,
cat /etc/resolv.conf
最下面就多了2行:
# Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8)
# DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN
nameserver 8.8.8.8
nameserver 8.8.4.4
再次執行
sudo apt-get update
可以正常更新了。
此方法也可以用於解決無法安裝Apache,出現類似下列錯誤時:
E: Failed to fetch http://security.ubuntu.com/ubuntu/pool/main/a/apache2/apache2-utils_2.4.18-2ubunt