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錯誤時,一定要檢查當前我們用的是什么用戶執行命令,以及該用戶對應的環境變量是否顯示聲明了代理服務器。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM