WSL
WSL 是 Windows 下的 Linux 子系统,提供了原生而非移植的 Linux 环境。
WSL 在虚拟机里运行 Linux 内核,因此理论上所有 Linux 能运行的软件 WSL 都能运行。
在较新的 Windows 机器上安装 WSL 非常简单
# 下载默认的发行版wsl --install# 下载特定的发行版wsl --install Ubuntu-24.04WSL 提供了多种 Linux 发行版,一般来说选择 Ubuntu 就行
# 查看所有可下载的发行版wsl -l -o# 查看目前已下载的发行版wsl -l -vWSL 使用起来也非常简单
# 启动特定的发行版wsl -d Ubuntu-24.04# 将发行版设为默认值wsl --set-default Ubuntu-24.04# 终止所有正在运行的虚拟机wsl --shutdownWSL 还有更高级的用法,比如可以像 sh 一样执行单条命令
# 用默认发行版运行命令wsl date# 可以添加参数wsl uname -aWSL 本质上是个虚拟机,而虚拟机的网络连接方式略微有点复杂,尤其是在宿主机使用了网络代理工具的情况下。
我目前的解决方案是使用 Steamcommunity_302。由于我在 WSL 里遇到的网络问题大多和 Git 有关,因此补充了相关配置
-
复制 SSL 证书到自定义的位置
Terminal window mkdir -p ~/.certscat /etc/ssl/certs/ca-certificates.crt > ~/.certs/git-ca-bundle.crt -
追加 Steamcommunity_302 的根证书
Terminal window print "\n# Steamcommunity_302\n" >> ~/.certs/git-ca-bundle.crt # 可选,添加一些说明cat /path/to/Steamcommunity_302/steamcommunityCA.pem >> ~/.certs/git-ca-bundle.crt -
修改 git 的证书位置
Terminal window git config --global http.sslCAInfo ~/.certs/git-ca-bundle.crt -
在 Windows 文件系统中运行 Steamcommunity_302,然后 WSL 里就可以正常使用 Git 了