当前位置: 首页>>技术教程>>正文


运行apt-get更新时发生“failed to fetch”错误。我该如何解决?

, , , ,

问题描述

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

我已经阅读了几十个来自askubuntu.com的apt-get更新问题,其中“未能获取”错误并尝试了解决方案。不幸的是,没有人工作我刚刚在我的笔记本电脑上安装了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,他的更新似乎没有问题。我们共享相同的连接,所以我认为互联网连接问题不可能是错误的原因。

尝试的解决方案:

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

nameserver 8.8.8.8
nameserver 8.8.4.4

错误仍然存​​在。

herehere,我反复更改了要在更新管理器和软件源设置中使用的镜像服务器。同样,错误仍然存​​在。

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

最后,apt-get更新无法获取文件,“临时故障解决…”错误建议运行以下内容:

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

## N.B. 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

## N.B. 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

## N.B. 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

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

使用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的输出:

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

如果现在解析失败,则在桌面顶部栏中的网络指示器上显示right-click,单击编辑连接,选择您的连接,单击编辑| IPv4设置。仅将方法从自动(DHCP)更改为自动(DHCP)地址,并在“其他DNS服务器”字段中输入8.8.8.8。单击保存….确认/etc/resolv.conf现在包含行名称服务器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个方框:

    12.04,updates,software-sources,ping,ubuntu

  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/)

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

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

参考资料

本文由Ubuntu问答整理, 博文地址: https://ubuntuqa.com/article/6220.html,未经允许,请勿转载。