【问题标题】:WSL throws (6) Could not resolve host: raw.githubusercontent.com when trying to install NVM and cant ping google.comWSL 抛出 (6) Could not resolve host: raw.githubusercontent.com 在尝试安装 NVM 时无法 ping google.com
【发布时间】:2022-12-01 09:46:44
【问题描述】:

尝试在 Windows 11 上使用 wsl 2 安装 nvm 时,它会抛出:

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.2/install.sh | bash
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:--  0:00:09 --:--:--     0curl: (6) Could not resolve host: raw.githubusercontent.com

当我尝试ping google.com时出错,而ping 8.8.8.8有效!?!

【问题讨论】:

    标签: windows-subsystem-for-linux wsl-2 nvm windows-11


    【解决方案1】:

    你可以尝试运行这个

    sudo rm /etc/resolv.conf
    sudo bash -c 'echo "nameserver 8.8.8.8" > /etc/resolv.conf'
    sudo bash -c 'echo "[network]" > /etc/wsl.conf'
    sudo bash -c 'echo "generateResolvConf = false" >> /etc/wsl.conf'
    sudo chattr +i /etc/resolv.conf
    

    它会删除你运行 WSL 时自动生成的 resolve.config 文件,然后创建一个新文件并放入“nameserver 8.8.8.8”,然后创建一个 wsl.conf 文件并添加 [network] 和 generateResolveConf = false 以防止自动生成文件

    你也可以跑

    cat /etc/resolv.conf
    

    检查文件的内容

    ping google.com
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-04-22
      • 2017-09-21
      相关资源
      最近更新 更多