apt-get update 101错误解决办法

在一次装好Ubuntu系统, 执行

sudo apt-get update

时,报了错

"

W: Failed to fetch http://security.ubuntu.com/ubuntu/dists/raring-security/Release.gpg Cannot initiate the connection to security.ubuntu.com:80 (2001:67c:1562::13). - connect (101: Network is unreachable) [IP: 2001:67c:1562::13 80]

"

一开始以为是Ubuntu默认的源访问不到,于是通过编辑文件 /etc/apt/sources.list,修改源的方式,尝试去解决问题

先备份sources.list文件,然后把原来的sources.list的文件改为一下内容

deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb 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 main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse

发现依然有这个错误。

看了报错信息,以为是DNS解析有误,导致访问不到域名所对应的服务器内容,于是尝试添加DNS服务器来解决问题,具体为修改/etc/resolv.conf文件

按照以下格式将代码添加到文件最后,用以添加DNS服务器,我添加的是Google的DNS服务器

nameserver 8.8.8.8

发现还是有这个问题。

最后用搜索引擎搜了一下apt-get update错误信息101,发现有人提出,报错信息里给出的IP地址是IPV6,所以可能是系统的IPV6代理没有设置好。(因为公司内网默认隔离,如果不设置公司的代理服务器,就无法访问外网)

我观察了一下,在UI的系统设置界面里,我设置好了,但是还是报错。

于是尝试着在系统文件里设置,具体方法是编辑文件~/.bashrc

在文件的最后加入以下内容

#Set Proxy Server
export http_proxy="http://<proxy_name>:<port_number>" 
export https_proxy="https://<proxy_name>:<port_number>"

然后执行下面的命令让修改生效

source ~/.bashrc

 

由于显式的export了ipv4(http)和ipv6(https)的代理,ipv6已可以访问,最后sudo apt-get update执行成功了。

 

值得注意的是,我们在执行"$sudo apt-get install"和''#apt-get install"时,坏境变量是不一样的,前者是当前普通用户的环境变量,后者是系统环境变量,因此如果当我们还是发生101错误时,一定要检查当前我们用的是什么用户执行命令,以及该用户对应的环境变量是否显示声明了代理服务器。

posted @ 2019-08-08 17:38  青山牧云人  阅读(2146)  评论(0编辑  收藏  举报