更新时“某些索引文件无法下载”

运行sudo apt-get update出现以下错误:

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

我使用的是Ubuntu 12.04。 这是我从窗口安装程序安装Ubuntu后使用的命令。 我相信我的笔记本电脑已连接到互联网。 我现在能做什么?

只需打开synaptic manager,安装/重新安装ubuntu-extras-keyring然后(在终端中)输入sudo apt-get update

欢呼你会从这个错误中解脱出来。

正如vasa1指出的那样 ,您的系统配置用于下载软件包以进行安装的服务器目前已关闭

下载镜像关闭时该怎么办…

该问题的解决方案是使用将其更改为不同的镜像(即,不同的服务器)。

选项1:使用图形配置实用程序

开放软件源

Alt + F2 ,键入gksu software-properties-gtk ,然后输入您的密码。 (或者,选择Update Manager左下角的设置… ,或转到设置> Synaptic中的存储库)。

  • 那是你正在运行的Ubuntu 10.04 LTS。 在以后的版本中,您只需运行software-properties-gtk ,当您进行更改时,PolicyKit将对您进行身份validation。
  • 大多数使用较新版本的人都有软件中心,而不是Synaptic。 在软件中心,您将转到编辑 > 软件源…。
  • Update Manager未更改,但在新版本中称为Software Updater。

更改下载服务器

在“软件源”窗口的“ Ubuntu软件”选项卡中,有一个标记为“ 下载自”的下拉菜单。 选择您的区域服务器。 例如,我在美国,它在我的11.10机器上看起来像这样:

“软件源”窗口显示在下拉菜单中选择的“美国服务器”。
“软件源”窗口显示在“从下载”下拉菜单中选择的美国服务器

您可能会看到该短列表中列出的其他服务器(如您当前设置的服务器)。

您也可以使用主服务器,但它几乎总是比使用区域服务器慢得多。 (至少在美国,无论如何。)

如果要使用其他镜像,可以通过单击其他…来查看镜像列表。

在“软件源”中选择“下载服务器”对话框,以选择备用镜像

选项2:手动编辑配置文件

备份和打开sources.list

备份sources.list文件并在文本编辑器中打开它:

 cd /etc/apt sudo cp sources.list sources.list.old gksu gedit sources.list 
  • 如果您已经运行了第二行,请不要再次执行此操作,除非您要使用新配置的副本覆盖旧备份。
  • 对于基于文本的编辑器(不需要任何GUI),将第三行替换为sudo nano -w sources.list (或sudo vi sources.listsudo -e sources.list )。

在文本编辑器中,使用新服务器名称替换旧服务器名称的每个实例。 例如,您可以使用ubuntuarchive.hnsdc.com替换ubuntuarchive.hnsdc.com每个实例。 (无论您使用哪种文本编辑器,都可以实现此目的 – 您无需手动查找每个实例并输入新镜像的名称。)

保存文件,退出文本编辑器,运行sudo apt-get update ,它应该与新服务器一起使用。

选项3:命令行替换

sed允许您编写简单(或复杂)的脚本,这些脚本一次一行地作用于文件。 因此,您可以发出通过sources.list的单个命令,用新服务器名称替换旧服务器名称的所有实例。

首先,进入/etc/apt和(除非你最近这样做)备份文件:

 cd /etc/apt sudo cp sources.list sources.list.old 

然后运行sed

 sudo cp sources.list sources.list.tmp sed 's/ ubuntuarchive.hnsdc.com / us.archive.ubuntu.com /' sources.list.tmp | sudo tee sources.list sudo rm sources.list.tmp 
  • 对于除ubuntuarchive.hnsdc.com之外的旧服务器,请根据需要进行更改。
  • 对于除us.archive.ubuntu.com之外的新服务器,请根据需要进行更改。
  • 我决定将sources.list复制到一个临时文件中,并将其用作sed的输入。 这是确保sed在读取文件时不会覆盖文件的一种方法。
  • 这里的sed “脚本”非常简单。 这解释了替代如何运作。

但是有哪些下载服务器?

有超过400个注册的Ubuntu镜像用于安装和更新软件。

这些称为归档镜像 。 这不应与CD镜像相混淆,其中存储了用于安装Ubuntu的 ISO映像和相关文件。

许多服务器都提供这两种服务器,因此都是存档镜像和CD镜像。 但很多只是其中之一。

镜像已关闭或您的Internet连接有问题(可能是临时的)。

  • 确保你可以ping 谷歌DNSarchive.ubuntu.com

    ping -c3 archive.ubuntu.com
    ping -c3 8.8.8.8

    这两个命令都应该在统计行中返回0% packet loss 。 否则你的互联网连接已关闭。

  • 如果您的连接看起来很好,则可能是镜像已关闭。 尝试选择靠近您所在位置的另一个。

去终端并按照以下步骤解决问题……

 sudo su (login as root) cd /var/lib/apt/lists/ rm -fr * cd /etc/apt/sources.list.d/ rm -fr * cd /etc/apt sudo cp sources.list sources.list.old sudo cp sources.list sources.list.tmp sed 's/ubuntuarchive.hnsdc.com/us.archive.ubuntu.com/' sources.list.tmp | sudo tee sources.list sudo rm sources.list.tmp* apt-get clean apt-get update