由于安全问题,无法在 WSL Ubuntu 中使用 apt

由于安全问题,无法在 WSL Ubuntu 中使用 apt

我正在尝试在 Windows 计算机上的 WSL 实例上安装make。因此,我尝试了以下命令:

sudo apt install make

输入我的凭证并按回车键后,我得到了以下输出:

Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
Suggested packages:
  make-doc
The following NEW packages will be installed:
  make
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
Need to get 180 kB of archives.
After this operation, 426 kB of additional disk space will be used.
Ign:1 http://archive.ubuntu.com/ubuntu jammy/main amd64 make amd64 4.3-4.1build1
Ign:1 http://archive.ubuntu.com/ubuntu jammy/main amd64 make amd64 4.3-4.1build1
Ign:1 http://archive.ubuntu.com/ubuntu jammy/main amd64 make amd64 4.3-4.1build1
Err:1 http://archive.ubuntu.com/ubuntu jammy/main amd64 make amd64 4.3-4.1build1
  Temporary failure resolving 'archive.ubuntu.com'
E: Failed to fetch http://archive.ubuntu.com/ubuntu/pool/main/m/make-dfsg/make_4.3-4.1build1_amd64.deb  Temporary failure resolving 'archive.ubuntu.com'
E: Unable to fetch some archives, maybe run apt-get update or try with --fix-missing?

我还知道,在我的本地机器上,有一个与获取证书相关的相当严格的安全系统。在使用 pip 安装 Python 包时,我经常必须使用诸如--trusted-host或其他方法来绕过认证或 SSL。

我不确定这两件事是否相关,但运行相同的apt命令--allow-unauthenticated没有任何区别。运行apt-get update结果如下:

Ign:1 http://security.ubuntu.com/ubuntu jammy-security InRelease
Ign:2 http://archive.ubuntu.com/ubuntu jammy InRelease
Ign:3 http://archive.ubuntu.com/ubuntu jammy-updates InRelease
Ign:1 http://security.ubuntu.com/ubuntu jammy-security InRelease
Ign:4 http://archive.ubuntu.com/ubuntu jammy-backports InRelease
Ign:1 http://security.ubuntu.com/ubuntu jammy-security InRelease
Ign:2 http://archive.ubuntu.com/ubuntu jammy InRelease
Err:1 http://security.ubuntu.com/ubuntu jammy-security InRelease
  Temporary failure resolving 'security.ubuntu.com'
Ign:3 http://archive.ubuntu.com/ubuntu jammy-updates InRelease
Ign:4 http://archive.ubuntu.com/ubuntu jammy-backports InRelease
Ign:2 http://archive.ubuntu.com/ubuntu jammy InRelease
Ign:3 http://archive.ubuntu.com/ubuntu jammy-updates InRelease
Ign:4 http://archive.ubuntu.com/ubuntu jammy-backports InRelease
Err:2 http://archive.ubuntu.com/ubuntu jammy InRelease
  Temporary failure resolving 'archive.ubuntu.com'
Err:3 http://archive.ubuntu.com/ubuntu jammy-updates InRelease
  Temporary failure resolving 'archive.ubuntu.com'
Err:4 http://archive.ubuntu.com/ubuntu jammy-backports InRelease
  Temporary failure resolving 'archive.ubuntu.com'
Reading package lists... Done
W: Failed to fetch http://archive.ubuntu.com/ubuntu/dists/jammy/InRelease  Temporary failure resolving 'archive.ubuntu.com'
W: Failed to fetch http://archive.ubuntu.com/ubuntu/dists/jammy-updates/InRelease  Temporary failure resolving 'archive.ubuntu.com'
W: Failed to fetch http://archive.ubuntu.com/ubuntu/dists/jammy-backports/InRelease  Temporary failure resolving 'archive.ubuntu.com'
W: Failed to fetch http://security.ubuntu.com/ubuntu/dists/jammy-security/InRelease  Temporary failure resolving 'security.ubuntu.com'
W: Some index files failed to download. They have been ignored, or old ones used instead.

答案1

您的 WSL 实例似乎在解析包源时遇到困难,这可能是由于 DNS 问题造成的。我遇到了类似的问题,以下步骤帮助我解决了该问题:

检查文件/etc/resolv.conf存在并包含有效的 DNS 服务器。您可以使用以下命令创建文件并设置 DNS 服务器:

touch /etc/resolv.conf
echo "nameserver 8.8.8.8" > /etc/resolv.conf

这将创建文件并将 Google 的 DNS 服务器 (8.8.8.8) 设置为名称服务器。如有必要,您可以使用其他 DNS 服务器。

重试安装包:

sudo apt install make

这应该可以解决问题。就我的情况而言,仅此一步就足够了。

相关内容