在Ubuntu更新中,谁没碰上个错误?这事儿在Ubuntu以及各类基于Ubuntu的Linux发行版里,简直跟家常便饭似的。错误原因五花八门,但修复起来通常并不复杂。这篇文章就把Ubuntu里那些频繁冒头的更新错误挨个捋一遍,顺便告诉你该怎么修。
合并列表问题
终端里跑更新命令,时不时就会撞上“合并列表错误”,具体表现大概长这样:
E:Encountered a section with no Package: header,
E:Problem with MergeList /var/lib/apt/lists/archive.ubuntu.comubuntudistspreciseuniversebinary-i386Packages,
E:The package lists or status file could not be parsed or opened.’
要想搞定它,两条命令就能解决:
sudo rm -r /var/lib/apt/lists/*
sudo apt-get clean && sudo apt-get update
下载仓库信息失败 — 类型一
下载仓库信息失败其实分两种。先说第一种,错误信息一般是这样的:
W:Failed to fetch bzip2:/var/lib/apt/lists/partial/in.archive.ubuntu.comubuntudistsoneiricrestrictedbinary-i386Packages Hash Sum mismatch,
W:Failed to fetch bzip2:/var/lib/apt/lists/partial/in.archive.ubuntu.comubuntudistsoneiricmultiversebinary-i386Packages Hash Sum mismatch,
E:Some index files failed to download. They ha ve been ignored, or old ones used instead
处理方式也很直接:
sudo rm -rf /var/lib/apt/lists/*
sudo apt-get update
下载仓库信息失败 — 类型二
另一种“下载仓库信息失败”的根源往往是PPA过时了。当你打开更新管理器,看到下面这样的错误时:

别急,先运行 sudo apt-get update,看看是哪个PPA翻车了,然后把它从源列表里删掉就行。具体操作可以参考之前写过的截图指南。
下载包文件失败错误
类似的问题还有“下载包文件失败”,错误提示如下图:

修复起来超级简单——把软件源改回主服务器就行。打开“软件和更新”,在“下载自”那里选择主服务器:

部分更新错误
终端里跑更新时,偶尔还会碰到“部分更新错误”:
Not all updates can be installed
Run a partial upgrade, to install as many updates as possible
这时候一条命令就够了:
sudo apt-get install -f
加载共享库时发生错误
严格来说这算是安装错误,不过也经常发生在更新流程里。如果你从源码编译安装程序,可能会看到:
error while loading shared libraries:
cannot open shared object file: No such file or directory
修复方法:终端里运行 sudo /sbin/ldconfig -v。更详细的说明可以翻翻之前那篇专门讲这个错误的文章。
无法获取锁 /var/cache/apt/archives/lock
这个错误多半是因为另一个程序正在使用APT。比如你一边在Ubuntu软件中心装东西,一边又在终端里敲apt命令,就会看到:
E: Could not get lock /var/cache/apt/archives/lock – open (11: Resource temporarily una vailable)
E: Unable to lock directory /var/cache/apt/archives/
通常把所有用到apt的程序关掉就没事了。如果问题顽固不化,试试:
sudo rm /var/lib/apt/lists/lock
不行的话再来:
sudo killall apt-get
更多细节可以参考专门的文章。
GPG错误:下列签名无法验证
添加PPA之后,更新时可能会报GPG签名错误,比如:
W: GPG error: https://repo.mate-desktop.org saucy InRelease: The following signatures couldn’t be verified because the public key is not a vailable: NO_PUBKEY 68980A0EA10B4DE8
解决方案是把公钥导入系统。从错误信息里找到密钥号(上面例子是 68980A0EA10B4DE8),然后执行:
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 68980A0EA10B4DE8
导入完成后再次更新,一切正常。
BADSIG错误
另一个跟签名相关的错误是BADSIG,长这样:
W: A error occurred during the signature verification. The repository is not updated and the previous index files will be used. GPG error: https://extras.ubuntu.com precise Release: The following signatures were invalid: BADSIG 16126D3A3E5C1192 Ubuntu Extras Archive Automatic Signing Key
W: GPG error: https://ppa.launchpad.net precise Release:
The following signatures were invalid: BADSIG 4C1CBC1B69B0E2F4 Launchpad PPA for Jonathan French W: Failed to fetch https://extras.ubuntu.com/ubuntu/dists/precise/Release
修复BADSIG错误,终端里按顺序跑这几条命令:
sudo apt-get clean
cd /var/lib/apt
sudo mv lists oldlist
sudo mkdir -p lists/partial
sudo apt-get clean
sudo apt-get update
上面汇总了Ubuntu更新时最常见的几类错误,希望能帮你少走弯路。你如果遇到过其他类型的更新错误,欢迎在评论区分享,我会尽量整理出快速解决指南。
其他网友的补充
更新源出现问题
E: Problem executing scripts APT::Update::Post-Invoke-Success 'if /usr/bin/test -w /var/cache/app-info -a -e /usr/bin/appstreamcli; then appstreamcli refresh > /dev/null; fi'
E: Sub-process returned an error code
解决办法:
sudo pkill -KILL appstreamcli
wget -P /tmp https://launchpad.net/ubuntu/+archive/primary/+files/appstream_0.9.4-1ubuntu1_amd64.deb https://launchpad.net/ubuntu/+archive/primary/+files/libappstream3_0.9.4-1ubuntu1_amd64.deb
sudo dpkg -i /tmp/appstream_0.9.4-1ubuntu1_amd64.deb /tmp/libappstream3_0.9.4-1ubuntu1_amd64.deb
然后再次更新即可。
E: GPG 错误:https://mirrors.163.com precise Release: 下列签名无效: NODATA 1 NODATA 2
这个错误通常表示网络没连上,检查一下网络状态。
E: 无法获得锁 /var/lib/apt/lists/lock - open (11: 资源暂时不可用) E: 无法对目录 /var/lib/apt/lists/ 加锁
这个问题的原因是更新时中途中断了。只要在终端里输入:
sudo rm /var/lib/apt/lists/lock
就能解除锁定,继续正常操作。
