背景
我的系统是Ubuntu20.04.2,x86的cpu,使用cuda11。
打算更新apt-get
使用命令
apt-get upate
但是遇到报错
E: Failed to fetch https://developer.download.nvidia.cn/compute/cuda/repos/ubuntu2004/x86_64/by-hash/SHA256/ce4d38aa740e318d2eae04cba08f1322017d162183c8f61f84391b
f88020a534 404 Not Found [IP: 36.27.222.153 443]
E: Some index files failed to download. They have been ignored, or old ones used instead.
尝试的过程:
1.首先尝试给apt-get换源,将下方代码覆盖或添加进/etc/apt/sources.list的内容
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-updates main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-updates main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-backports main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-backports main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-security main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-security main restricted universe multiverse
但还是报相同的错误。
2.查了cuda的安装方式
https://blog.csdn.net/tanmx219/article/details/86210023
但感觉我的问题应该出在cuda源上,不是安装的问题
3.科学上网查查
在github上看到一种解决办法,更换key
apt-key adv --fetch-keys https://developer.download.nvidia.cn/compute/cuda/repos/ubuntu2004/x86_64/7fa2af80.pub
但apt-get upate依旧失败
解决方案
然后我又看到一位大佬的的建议
When following the cuda+wsl instruction, you should replace nvida.com to redirect location: nvida.cn as shown.Which means:
apt-key adv --fetch-keys https://developer.download.nvidia.cn/compute/cuda/repos/ubuntu2004/x86_64/7fa2af80.pub
sh -c 'echo "deb http://developer.download.nvidia.cn/compute/cuda/repos/ubuntu2004/x86_64 /" > /etc/apt/sources.list.d/cuda.list'
虽然他说的是WSL,但我查看了一下我的cuda源
cat /etc/apt/sources.list.d/cuda.list
# deb http://developer.download.nvidia.com/compute/cuda/repos/ubuntu2004/x86_64 /
于是我在第三步的基础上,执行
echo "deb http://developer.download.nvidia.cn/compute/cuda/repos/ubuntu2004/x86_64 /" > /etc/apt/sources.list.d/cuda.list
更换cuda源
apt-get update
# ...
# Reading package lists... Done
成功!
总结
其实就只是把cuda源中的nvidia.com改为nvidia.cn,但找了很久,估计是我不小心换其他源的时候换错了,因此记录一下(防止下次再犯)。