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

jow*_*els 49 updates software-sources ping 12.04

与上面的注释相反,我还没有找到我的问题的答案。

我已经阅读了近十二个 apt-get 更新问题,其中大部分来自 askubuntu.com,其中包含“无法获取”错误,并尝试了在那里回答的解决方案。不幸的是,没有一个奏效。我最近在笔记本电脑上安装了 Ubuntu 12.04,与 Windows 7 一起双启动。当我尝试时

sudo apt-get update
Run Code Online (Sandbox Code Playgroud)

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

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.
Run Code Online (Sandbox Code Playgroud)

注意

这在我安装 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
Run Code Online (Sandbox Code Playgroud)

错误仍然发生。

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

我还尝试编辑我的来源列表,取消选中带有“独立”的行(如建议的那样)。根据here,我尝试删除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
Run Code Online (Sandbox Code Playgroud)

可悲的是,没有什么对我有用。在我去过的所有论坛中,与 相关的答案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
Run Code Online (Sandbox Code Playgroud)

以下是针对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
Run Code Online (Sandbox Code Playgroud)

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

使用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
Run Code Online (Sandbox Code Playgroud)

的输出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
Run Code Online (Sandbox Code Playgroud)

Rie*_*lus 31

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

  1. 获取您的 Ubuntu 版本的发行版,在控制台中输入:

    lsb_release -r
    
    Run Code Online (Sandbox Code Playgroud)
  2. http://repogen.simplylinux.ch/生成一个新的sources.list

  3. 选择您所在的国家/地区发布
  4. 选中前 12 个框:

    所有 Ubuntu 分支 + 安全和更新

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

    mv /etc/apt/sources.list /etc/apt/sources.list.old
    
    Run Code Online (Sandbox Code Playgroud)
  7. 您现在可以通过执行以下操作打开 vi 以保存新列表:

    vi /etc/apt/sources.list
    (Paste and save using `:wq`)
    
    Run Code Online (Sandbox Code Playgroud)

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

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

  • 我决定回答这个问题,尽管作者的问题以不同的方式解决。他的问题是与损坏的 source.list 文件(偶然发现 3 次)相关的许多问题的最佳结果,我觉得把我的解决方案留在这里,因为它可以为我节省很多时间。 (2认同)

jdt*_*ood 29

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

sudo gedit /etc/resolv.conf
Run Code Online (Sandbox Code Playgroud)

并添加行

nameserver 8.8.8.8
Run Code Online (Sandbox Code Playgroud)

并保存。然后做

ping www.google.com
Run Code Online (Sandbox Code Playgroud)

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

sudo apt-get --download-only --reinstall install resolvconf
sudo dpkg --purge --force-depends resolvconf
sudo apt-get install resolvconf
Run Code Online (Sandbox Code Playgroud)

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

  • @guntbert 嗯。您正在与 resolvconf 包的作者交谈。我想他知道他在说什么。;-) (6认同)
  • 当我按照这些步骤操作时,运行第一个命令后出现此错误:`Err http://us.archive.ubuntu.com/ubuntu/wily/main resolvconf all 1.77ubuntu1 404 Not Found [IP: 91.189.91.23 80 ] E:无法获取 http://us.archive.ubuntu.com/ubuntu/pool/main/r/resolvconf/resolvconf_1.77ubuntu1_all.deb 404 Not Found [IP: 91.189.91.23 80] ` (3认同)

jow*_*els 7

sudo apt-get update终于工作了!我刚刚意识到问题不在于系统,而在于系统如何从互联网连接和检索数据。我刚刚配置我的网络设置,改变了代理检测到Manual并填充在HTTPHTTPSFTP,和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/)
Run Code Online (Sandbox Code Playgroud)

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

不管怎样,谢谢大家的帮助!:)