运行apt-get update时会发生“无法获取”错误。 我该如何解决?

与上面的说明相反,我没有找到问题的答案。

我已经阅读了几十个apt-get更新问题,大多数来自askubuntu.com,“未能获取”错误并尝试了解决方案。 不幸的是,没有人奏效 我刚刚在我的笔记本电脑上安装了Ubuntu 12.04,双启动它与Windows 7一起。当我尝试时

sudo apt-get update 

在终端上,以下不断发生:

 Err http://ph.archive.ubuntu.com precise InRelease Err http://ph.archive.ubuntu.com precise-updates InRelease Err http://ph.archive.ubuntu.com precise-backports InRelease Err http://ph.archive.ubuntu.com precise Release.gpg Unable to connect to ph.archive.ubuntu.com:http: [IP: 91.189.92.177 80] Err http://ph.archive.ubuntu.com precise-updates Release.gpg Unable to connect to ph.archive.ubuntu.com:http: [IP: 91.189.92.177 80] Err http://ph.archive.ubuntu.com precise-backports Release.gpg Unable to connect to ph.archive.ubuntu.com:http: [IP: 91.189.92.177 80] Err http://extras.ubuntu.com precise InRelease Err http://extras.ubuntu.com precise Release.gpg Unable to connect to extras.ubuntu.com:http: Err http://security.ubuntu.com precise-security InRelease Err http://security.ubuntu.com precise-security Release.gpg Unable to connect to security.ubuntu.com:http: [IP: 91.189.92.190 80] Reading package lists... Done W: Failed to fetch http://ph.archive.ubuntu.com/ubuntu/dists/precise/InRelease W: Failed to fetch http://ph.archive.ubuntu.com/ubuntu/dists/precise-updates/InRelease W: Failed to fetch http://ph.archive.ubuntu.com/ubuntu/dists/precise-backports/InRelease W: Failed to fetch http://security.ubuntu.com/ubuntu/dists/precise-security/InRelease W: Failed to fetch http://extras.ubuntu.com/ubuntu/dists/precise/InRelease W: Failed to fetch http://ph.archive.ubuntu.com/ubuntu/dists/precise/Release.gpg Unable to connect to ph.archive.ubuntu.com:http: [IP: 91.189.92.177 80] W: Failed to fetch http://ph.archive.ubuntu.com/ubuntu/dists/precise-updates/Release.gpg Unable to connect to ph.archive.ubuntu.com:http: [IP: 91.189.92.177 80] W: Failed to fetch http://ph.archive.ubuntu.com/ubuntu/dists/precise-backports/Release.gpg Unable to connect to ph.archive.ubuntu.com:http: [IP: 91.189.92.177 80] W: Failed to fetch http://extras.ubuntu.com/ubuntu/dists/precise/Release.gpg Unable to connect to extras.ubuntu.com:http: W: Failed to fetch http://security.ubuntu.com/ubuntu/dists/precise-security/Release.gpg Unable to connect to security.ubuntu.com:http: [IP: 91.189.92.190 80] W: Some index files failed to download. They have been ignored, or old ones used instead. 

注意

这是在我安装Ubuntu 12.04后立即发生的。 我对Linux / Ubuntu世界非常陌生,对于这类东西我是个新手。

Update Manager(和软件中心)设置中的“源”列表很短。 它只包含2行“Canonical”,2行“Independent”,另外2行。 我认为这个列表很简短,因为它是一个新安装的Ubuntu。

连接到互联网似乎很好,我的朋友,他的笔记本电脑刚刚安装Ubuntu 12.04与我的同一时间,他的更新似乎没有问题。 我们共享相同的连接,所以我认为互联网连接问题不可能是错误的原因。

尝试的解决方案

从这里开始 ,我在/etc/resolvconf/resolv.conf.d周围进行了探索,并在/etc/resolvconf/resolv.conf.d添加了以下内容:

 nameserver 8.8.8.8 nameserver 8.8.4.4 

错误仍然存​​在。

从这里到这里 ,我反复更改了在Update Manager和Software sources设置中使用的Mirror服务器。 同样,错误仍然存​​在。

我也尝试编辑我的源列表,取消选中“独立”的行(如建议的那样)。 根据这里 ,我尝试删除源列表中的derb-src行。 仍然无济于事。

最后, 该网站建议运行以下内容:

 echo "nameserver 8.8.8.8" | sudo tee /etc/resolv.conf > /dev/null or, for a permanent solution, echo "nameserver 8.8.8.8" | sudo tee /etc/resolvconf/resolv.conf.d/base > /dev/null 

可悲的是,没有什么对我有用。 在我去过的所有论坛中,与nameserver 8.8.8.8相关的答案似乎最常出现。 还要注意我真的不明白解决方案,它们的含义或它们是如何完成的。 我只是跟着他们。

这是cat /etc/apt/sources.list的输出:

 # deb cdrom:[Ubuntu 12.04 LTS _Precise Pangolin_ - Release amd64 (20120425)]/ dists/precise/main/binary-i386/ # deb cdrom:[Ubuntu 12.04 LTS _Precise Pangolin_ - Release amd64 (20120425)]/ dists/precise/restricted/binary-i386/ # deb cdrom:[Ubuntu 12.04 LTS _Precise Pangolin_ - Release amd64 (20120425)]/ precise main restricted # See http://help.ubuntu.com/community/UpgradeNotes for how to upgrade to # newer versions of the distribution. deb http://archive.ubuntu.com/ubuntu precise main restricted deb-src http://archive.ubuntu.com/ubuntu precise main restricted ## Major bug fix updates produced after the final release of the ## distribution. deb http://archive.ubuntu.com/ubuntu precise-updates main restricted deb-src http://archive.ubuntu.com/ubuntu precise-updates main restricted ## NB software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu ## team. Also, please note that software in universe WILL NOT receive any ## review or updates from the Ubuntu security team. deb http://archive.ubuntu.com/ubuntu precise universe deb-src http://archive.ubuntu.com/ubuntu precise universe deb http://archive.ubuntu.com/ubuntu precise-updates universe deb-src http://archive.ubuntu.com/ubuntu precise-updates universe ## NB software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu ## team, and may not be under a free licence. Please satisfy yourself as to ## your rights to use the software. Also, please note that software in ## multiverse WILL NOT receive any review or updates from the Ubuntu ## security team. deb http://archive.ubuntu.com/ubuntu precise multiverse deb-src http://archive.ubuntu.com/ubuntu precise multiverse deb http://archive.ubuntu.com/ubuntu precise-updates multiverse deb-src http://archive.ubuntu.com/ubuntu precise-updates multiverse ## NB software from this repository may not have been tested as ## extensively as that contained in the main release, although it includes ## newer versions of some applications which may provide useful features. ## Also, please note that software in backports WILL NOT receive any review ## or updates from the Ubuntu security team. deb http://archive.ubuntu.com/ubuntu precise-backports main restricted universe multiverse deb-src http://archive.ubuntu.com/ubuntu precise-backports main restricted universe multiverse deb http://archive.ubuntu.com/ubuntu precise-security main restricted deb-src http://archive.ubuntu.com/ubuntu precise-security main restricted deb http://archive.ubuntu.com/ubuntu precise-security universe deb-src http://archive.ubuntu.com/ubuntu precise-security universe deb http://archive.ubuntu.com/ubuntu precise-security multiverse deb-src http://archive.ubuntu.com/ubuntu precise-security multiverse ## Uncomment the following two lines to add software from Canonical's ## 'partner' repository. ## This software is not part of Ubuntu, but is offered by Canonical and the ## respective vendors as a service to Ubuntu users. # deb http://archive.canonical.com/ubuntu precise partner # deb-src http://archive.canonical.com/ubuntu precise partner ## This software is not part of Ubuntu, but is offered by third-party ## developers who want to ship their latest software. deb http://extras.ubuntu.com/ubuntu precise main deb-src http://extras.ubuntu.com/ubuntu precise main 

以下是cat /etc/resolv.conf

 # 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 127.0.0.1 search nip.upd.edu.ph 

有人指出答案在这里,但不幸的是,这也没有用。 我尝试选择不同的服务器,但“选择服务器”从未可用。 搜索最佳服务器产生“无合适服务器”结果。 我认为镜像服务器很好,再次,互联网连接似乎没有问题。

使用ping -c3 archive.ubuntu.comping -c3 8.8.8.8都会产生0% packet loss 。 8.8.8.8的ping有时会产生33% packet loss但大多数是0%。

输入nslookup google.com收益率

 Server: 127.0.0.1 Address: 127.0.0.1#53 

输出ps aux | grep dns ps aux | grep dns

 nobody 1761 0.0 0.0 33012 1284 ? S 17:04 0:00 /usr/sbin/dnsmasq --no-resolv --keep-in-foreground --no-hosts --bind-interfaces --pid-file=/var /run/sendsigs.omit.d/network-manager.dnsmasq.pid --listen-address=127.0.0.1 --conf- file=/var/run/nm-dns-dnsmasq.conf --cache-size=0 --proxy-dnssec joa 2197 0.0 0.0 13576 928 pts/0 S+ 17:10 0:00 grep --color=auto dns 

编辑/etc/resolv.conf 。 在终端窗口中运行

 sudo gedit /etc/resolv.conf 

并添加该行

 nameserver 8.8.8.8 

并保存。 然后做

 ping www.google.com 

如果成功,则运行以下命令

 sudo apt-get --download-only --reinstall install resolvconf sudo dpkg --purge --force-depends resolvconf sudo apt-get install resolvconf 

如果现在解析失败,则右键单击桌面顶部栏中的网络指示器,单击Edit Connections ,选择您的连接,单击Edit | IPv4 Settings 。 仅将方法从Automatic (DHCP)更改为Automatic (DHCP) addresses only并在“ Additional DNS servers字段中输入8.8.8.8 。 单击“ Save... 。 validation/etc/resolv.conf现在是否包含行nameserver 8.8.8.8 ,并且您仍然可以ping www.google.com

我遇到了同样的问题,并认为最简单的解决方案是重置/etc/apt/sources.list的来源。 为此,请按照下列步骤操作:

  1. 获取Ubuntu版本的发布,输入控制台:

     lsb_release -r 
  2. 转到http://repogen.simplylinux.ch/以生成新的sources.list

  3. 选择您所在的国家 /地区
  4. 检查前12个方框:

    所有Ubuntu Brances +安全和更新

  5. 生成并复制新列表
  6. 将旧文件备份到sources.list.old

     mv /etc/apt/sources.list /etc/apt/sources.list.old 
  7. 您现在可以通过执行以下操作打开vi来保存新列表:

     vi /etc/apt/sources.list (Paste and save using `:wq`) 

    或者通过将“curl”命令(包括更新的源列表的唯一URI)复制并粘贴到终端,因为它在repogen输出页面的“Sources List”下显示。

  8. G2G,重试运行apt-get update

sudo apt-get update终于工作了! 我刚刚意识到问题不在系统上,而是系统如何连接并从互联网上检索数据。 我刚配置了我的网络设置并将代理检测更改为Manual并填写了HTTPHTTPSFTPSocks Host空白我使用的代理。 当我再次更新时,此错误输出首先发生:

 E: Could not get lock /var/lib/dpkg/lock - open (11 Resource temporarily unavailable) E: Unable to lock the administration directory (/var/lib/dpkg/) 

嗯,不完全相同但与之相似(我从上面复制过 )。 但是当我再次尝试更新时,它终于工作了(我上面发布错误输出的原因而不是我看到的确切输出)我现在可以选择不同的镜像服务器了。 如果网络代理配置真的是我的困境的原因,那么,我有点觉得这样的基本错误是愚蠢的。

无论如何,感谢大家的帮助! 🙂

做这个

 sudo bash -c 'echo "nameserver 127.0.0.1" >> /etc/resolv.conf' 

然后做sudo apt-get update以查看它是否有效。