hash sum mismatch
APT hash sum mismatch错误的常见解决方法总结
linux报这个错误的时候,有很多的原因,通常是出现在使用
apt-get update
的时候, apt 的全称是Advanced Packaging Tool。在apt版本1.2.0之前,它是有BUG的,后续版本修正了,或许可以通过直接升级apt版本解决。问题原因五花八门,中外网友们的解决办法也是多种多样。
Hash sum mismatch这个错误是什么意思?
apt repository metadata is organized in such a way that a top level file contains the checksums of other pieces of repository metadata.
The “Hash sum mismatch” ERROR indicates to the user that apt has run a checksum against the repository metadata it has downloaded and the checksum apt computed does not match the checksum listed in the top level file.
Unfortunately, due to a bug in apt, metadata files compressed with lzma (.xz files) are occasionally downloaded (and in some cases) decompressed incorrectly resulting in a broken file. As a result, the checksum of the broken file will be incorrect and cause apt to produce the “Hash sum mismatch” error.
Hash sum mismatch 为何产生?
There are at least 3 ways this can hAPPen for most ubuntu and Debian based systems today:
Stale metadata cached between the client and server. This is unlikely in most cases and not possible if SSL is used.
The metadata does not match because of a bug during the extraction of the metadata.
The repository is being updated while an apt-get update is run, or apt has cached a stale Release file.
Users can avoid all 3 cases by: (如何避免?)
Using SSL.
Disabling XZ compressed metadata, or ensuring a newer version of APT is used.
Using the new Acquire-by-hash feature available in APT 1.2.0.
截图取自下文参考链接
参考链接4: Solution reference4
参考链接5: Solution reference5
怎么解决?总结能够Google到的常见解决方法
本人在遇到这个错误的时候,查到了很多方法,这些方法的都是有网友验证过的,具体哪种方法适用于读者的问题的解决,可以多尝试。下面,我就按照方法被应用频率的高低来阐述。
(1)清cache缓存:
$ sudo apt-get clean
$ sudo apt-get update --fix-missing
参考链接1:Solution reference1
(2)删除/var/lib/apt/lists/partial/中的下载文件:
$ sudo rm -R /var/lib/apt/lists/partial/*
$ sudo apt-get update && sudo apt-get upgrade
参考链接2:Solution reference2
(3)更换apt更新源:
有时候,因为处于GFW内、网速下载更新等原因,我们是使用UBUNTU的时候,改为国内的更新源更加方便 。校园网的话,使用edu.cn的源,比如中科大,其他的话可以使用网易、阿里等。
替换前做个副本备份先:
$ sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak
编辑源列表,加入国内源地址:
$ sudo gedit /etc/apt/sources.list
# 网易新开的更新源
deb http://mirrors.163.com/ubuntu/ intrepid main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ intrepid-security main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ intrepid-updates main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ intrepid-proposed main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ intrepid-backports main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ intrepid main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ intrepid-security main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ intrepid-updates main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ intrepid-proposed main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ intrepid-backports main restricted universe multiverse
# 或者, 加入如下内容(中科大的):
deb http://mirrors.ustc.edu.cn/ubuntu/ precise-updates main restricted
deb-src http://mirrors.ustc.edu.cn/ubuntu/ precise-updates main restricted
deb http://mirrors.ustc.edu.cn/ubuntu/ precise universe
deb-src http://mirrors.ustc.edu.cn/ubuntu/ precise universe
deb http://mirrors.ustc.edu.cn/ubuntu/ precise-updates universe
deb-src http://mirrors.ustc.edu.cn/ubuntu/ precise-updates universe
deb http://mirrors.ustc.edu.cn/ubuntu/ precise multiverse
deb-src http://mirrors.ustc.edu.cn/ubuntu/ precise multiverse
deb http://mirrors.ustc.edu.cn/ubuntu/ precise-updates multiverse
deb-src http://mirrors.ustc.edu.cn/ubuntu/ precise-updates multiverse
deb http://mirrors.ustc.edu.cn/ubuntu/ precise-backports main restricted universe multiverse
deb-src http://mirrors.ustc.edu.cn/ubuntu/ precise-backports main restricted universe multiverse
再更新列表:
$ sudo apt-get update
$ sudo apt-get upgrade
(4)指定apt下载文件的压缩格式或者设置Acquire-by-hash
的值:
指定apt下载文件的压缩格式
$ sudo rm -rf /var/lib/apt/lists/partial
$ sudo apt-get update -o Acquire::Compressiontypes::order::=gz
对于第二条命令:也可以设置下载文件的压缩格式为bz2
。
如果不想每次的对apt的配置进行第二条命令那样设置的话,可以这么做。
1, 创建一个新文件,
/etc/apt/apt.conf.d/99compression-workaround
2,添加文本
Acquire::CompressionTypes::Order:: "gz";
现在,apt-get update
将会优先使用gzip
格式压缩的元数据。
这么设置的目的是因为apt本身的bug(bug报告),真正的解决办法还是利用apt的新特性进行设置Acquire-by-hash的值为‘Yes’,参考里面没有讲到如何enable或者take advantage of 这个Acquire-by-hash的feature, 如果有读者朋友找到在哪儿设置,麻烦留言~
详情参考
参考链接4: Solution reference4
参考链接5: Solution reference5
或者直接试着升级一下apt,如果apt的版本比较低的话。
(5)对代理服务器进行设置:
还有些开发者遇到的问题,是因为公司的Proxy的设置。
如果读者朋友使用了Proxy,那么可以尝试,在/etc/apt/apt.conf.d/
目录下创建一个名称为99fixbadproxy 的文件
$ sudo gedit /etc/apt/apt.conf.d/99fixbadproxy
把以下文本复制到上述文件中,然后保存退出:
Acquire::http::Pipeline-depth 0;
Acquire::http::No-Cache true;
Acquire::BrokenProxy true;
运行更新命令
$ sudo apt-get update
参考链接6:Solution reference6
(6)检查下载源的服务器与你所处地区的时差,修正时间戳timestamp:
国外网站上的一个回答如下:
To figure out whether this issue is fixed, you can visit, for example, the page at https://apt.dockerproject.org/repo/dists/ubuntu-xenial/main/binary-AMD64/ and check the timestamp for the InRelease file.
Currently it still says 11:06 (UTC) which is the version of the file that has the wrong checksums. If it says a later time, then it has probably been fixed.
Now the time is 13:25 (UTC) and we are still waiting
参考链接7:Solution reference7
N.B. 如果读者朋友是在docker中使用dockerfile进行build新镜像出错了的话,可以参考我的下一篇。
官网的那个docker-whale镜像build代码,我运行是有错误的,报的错误也是这个Hash sum mismatch。但是与我们上述的方法还是有些区别,毕竟上面的情况,都是网友在物理主机下运行
apt-get update
得到的error,我们使用dockerfile进行build新镜像的时候,实际上是在容器里面,有一点不同。
相关阅读
The Summary of Resigned After 15 Days
自从6月25日离职以来,身体时好时坏,这15天里我主要照着书学习了springcloud 的 分布式配置中心搭建, 链路追踪sleuth 的搭建,利用sp
Excel中sumif函数的怎么使用的呢?具体怎么去进行的?今天,seo实验室小编就教大家在Excel中sumif函数操作的使用方法。Excel中sumif
Excle的Sumif函数如何使用?下面是小编为大家精心整理的关于Excle的Sumif函数如何使用?希望能够帮助到你们。条件求和函数Sumif1比
题目 样例 先求出图的所有连通分量,然后每个分量缩成一点,构成DAG图求入度为零的点(所代表的分量)就是我们需要单独通知的分量.
作为一个java开发者肯定都知道且使用HashMap,但估计大部分人都不太知道WeakHashMap。从类定义上来看,它和普通的HashMap一样,继承了A