运行 apt-get update 时出现“获取失败”错误。如何修复此问题?

运行 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 世界还很陌生,对于这类事情我还是个菜鸟。

更新管理器(和软件中心)设置中的源列表很短。它只包含 2 行“Canonical”,2 行“Independent”,以及另外 2 行。我认为列表很短是因为它是新安装的 Ubuntu。

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

尝试的解决方案

这里,我探索了一下/etc/resolvconf/resolv.conf.d并添加了/etc/resolvconf/resolv.conf.d/head以下内容:

nameserver 8.8.8.8
nameserver 8.8.4.4

仍然出现错误。

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

我还尝试编辑我的来源列表,取消选中上面有“独立”字样的行(按照建议)。根据这里,我尝试删除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

## 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

有人指出答案是这里但不幸的是,这也不起作用。我尝试选择不同的服务器,但“选择服务器”始终不可用。搜索最佳服务器时,得到的结果是“没有合适的服务器”。我认为镜像服务器没问题,而且互联网连接似乎没有问题。

使用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

答案1

编辑/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输入。单击。验证现在包含一行并且您仍然可以。8.8.8.8Additional DNS serversSave.../etc/resolv.confnameserver 8.8.8.8ping www.google.com

答案2

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

  1. 获取你的 Ubuntu 版本的发布信息,在控制台中输入:

    lsb_release -r
    
  2. http://repogen.simplylinux.ch/产生新的sources.list

  3. 选择您的国家&发布
  4. 勾选前 12 个框:

    所有 Ubuntu 分支 + 安全和更新

  5. 生成并复制您的新列表
  6. 备份旧文件至来源.列表.旧

    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 输出页面上的“源列表”下所示。

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

答案3

sudo apt-get update终于成功了!我刚刚意识到问题不在于系统,而在于系统如何连接和从互联网检索数据。我刚刚配置了我的网络设置,并将代理检测更改为,Manual并填写了HTTPHTTPS、 和FTP,并Socks 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/)

嗯,不完全一样,但类似(我上面复制自这里)。但当我再次尝试更新时,它终于成功了(这就是我发布上述错误输出而不是我看到的确切输出的原因),我现在可以选择不同的镜像服务器。如果网络代理配置真的是我遇到麻烦的原因,那么,我有点觉得自己犯了这么基本的错误很愚蠢。

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

答案4

我遇到了同样的错误,发现这是因为我添加了 armhf 架构。
运行此命令 -
sudo dpkg --print-foreign-architectures
最好删除任何新架构,因为并非所有存储库都有索引文件并导致此错误。
运行
sudo dpkg --remove-architecture <architecture name>
- 然后
sudo apt-get update
- 这为我解决了这个问题。
希望它有所帮助... :)

相关内容