ubuntu sudo apt-get update 失败 解决方法

在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

 

你可能感兴趣的:(ubuntu sudo apt-get update 失败 解决方法)