WSL子系统遇到网络不通报错Temporary failure resolving ‘archive.ubuntu.com‘
📌 解决方案
✅ 方法一:临时改 /etc/resolv.conf
在 WSL 里执行:
sudo bash -c "echo 'nameserver 8.8.8.8' > /etc/resolv.conf"
然后再执行:
sudo apt update sudo apt install htop
🔍 说明:
-
8.8.8.8
是 Google 公共 DNS,国内用223.5.5.5
(阿里)或者114.114.114.114
也行。
✅ 方法二:永久修复
-
禁止 WSL 自动生成 resolv.conf
sudo nano /etc/wsl.conf
添加:
[network] generateResolvConf = false
-
重启 WSL:
wsl --shutdown
然后再启动。
-
手动创建 resolv.conf:
sudo bash -c "echo 'nameserver 8.8.8.8' > /etc/resolv.conf" sudo chmod 644 /etc/resolv.conf
✅ 方法三:换国内源
如果 DNS 通了还是慢,可以把 apt 源也换成国内镜像:
sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak sudo nano /etc/apt/sources.list
换成:
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ noble main restricted universe multiverse deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ noble-updates main restricted universe multiverse deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ noble-security main restricted universe multiverse
然后:
sudo apt update sudo apt install htop
📌 📢 总结
✔ 先修 resolv.conf,能通 DNS
✔ 必要时改 apt 源
✔ 然后就能顺利安装 htop 和其他包了