You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Ubuntu WSL中无法下载/使用Git及相关工具问题求助

解决WSL Ubuntu网络下载卡顿及Git异常问题

1. 调整WSL DNS配置

  • 替换默认DNS并锁定配置文件,避免WSL自动覆盖:
    sudo rm /etc/resolv.conf
    sudo bash -c 'echo "nameserver 8.8.8.8" > /etc/resolv.conf'
    sudo bash -c 'echo "nameserver 1.1.1.1" >> /etc/resolv.conf'
    sudo chattr +i /etc/resolv.conf
    
  • 关闭WSL自动生成hosts功能:
    在Windows的%UserProfile%\.wslconfig文件中添加(无此文件则新建):
    [network]
    generateHosts = false
    
    执行wsl --shutdown重启WSL后生效。

2. 优化TCP网络参数

  • 临时调整传输缓冲区大小:
    sudo sysctl -w net.core.rmem_max=16777216
    sudo sysctl -w net.core.wmem_max=16777216
    sudo sysctl -w net.ipv4.tcp_rmem="4096 87380 16777216"
    sudo sysctl -w net.ipv4.tcp_wmem="4096 65536 16777216"
    
  • 永久生效:将上述命令内容添加到/etc/sysctl.conf文件末尾,重启WSL后自动加载。

3. 修复Git克隆卡顿

  • HTTPS克隆优化:禁用Gzip压缩
    git config --global core.compression 0
    
  • SSH克隆优化:编辑~/.ssh/config文件(无则新建):
    Host github.com
      Hostname github.com
      User git
      Compression no
      TCPKeepAlive yes
      ServerAliveInterval 30
      ServerAliveCountMax 10
    

4. 更换镜像源重新安装工具

  • 用国内镜像安装NVM:
    export NVM_NODEJS_ORG_MIRROR=https://npmmirror.com/mirrors/node
    curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
    
  • 用国内镜像安装Oh My Zsh:
    sh -c "$(curl -fsSL https://gitee.com/mirrors/oh-my-zsh/raw/master/tools/install.sh)"
    

5. 排查系统层面干扰

  • 临时关闭Windows防火墙测试,确认是否存在拦截。
  • 若使用代理,在WSL中配置对应环境变量:
    export http_proxy=http://你的代理地址:端口
    export https_proxy=http://你的代理地址:端口
    
    无需代理时执行unset http_proxy https_proxy清空变量。

内容的提问来源于stack exchange,提问作者Jeremy

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.08 07:25:21