最近重新要在Ubuntu上安装环境,所有的apt-get都会出现“Failed to fetch 404 Not Found” 错误
Err http://archive.ubuntu.com quantal/main amd64 Packages
404 Not Found [IP: 91.189.91.15 80]
Err http://archive.ubuntu.com quantal/restricted amd64 Packages
404 Not Found [IP: 91.189.91.15 80]
W: Failed to fetch http://security.ubuntu.com/ubuntu/dists/quantal-security/main/binary-amd64/Packages 404 Not Found [IP: 91.189.91.15 80]
W: Failed to fetch http://security.ubuntu.com/ubuntu/dists/quantal-security/restricted/binary-amd64/Packages 404 Not Found [IP: 91.189.91.15 80]
Err http://security.ubuntu.com raring-security/main amd64 Packages
404 Not Found [IP: 91.189.91.15 80]
Err http://security.ubuntu.com raring-security/restricted amd64 Packages
404 Not Found [IP: 91.189.91.15 80]
Err http://security.ubuntu.com raring-security/universe amd64 Packages
404 Not Found [IP: 91.189.91.15 80]
Err http://security.ubuntu.com raring-security/multiverse amd64 Packages
404 Not Found [IP: 91.189.91.15 80]</span>
为什么会出现此类错误?
Ubuntu 更新换代很快. 你的ubuntu一旦不是最新版本后,其仓库 (repository)就会被移到另外的服务器上面。所以不再是
http://archive.ubuntu.com/ubuntu/dist/ 这里能找到的。
如何解决?
-
最简单的方式是更新ubuntu到最新版本:(不一定可用,我使用还是会出现404)
sudo apt-get dist-upgrade
-
另外,你可以通过修改 /etc/apt/sources.list 来把链接指向旧的版本仓库:
-
使用以下实例代码将/etc/apt/sources.list中的所有 archive.ubuntu.com 和 security.ubuntu.com替换成 old-releases.ubuntu.com
-
sudo sed -i -e 's/archive.ubuntu.com\|security.ubuntu.com/old-releases.ubuntu.com/g' /etc/apt/sources.list
-
[可选]你可以再看看有没有 /etc/apt/sources.list.d/ 这个文件,可以把这个文件一起修改。以下是修改代码:
grep -E 'archive.ubuntu.com|security.ubuntu.com' /etc/apt/sources.list.d/*
-
然后执行更新语句:
sudo apt-get update
-
成功!