-
在C:\Users<你的用户名>下,新建.wslconfig文件
-
添加如下配置(具体配置参考官方文档):
Settings apply across all Linux distros running on WSL 2
[wsl2]
Limits VM memory to use no more than 4 GB, this can be set as whole numbers using GB or MB
memory=8GB
Sets the VM to use two virtual processors
processors=8
[experimental]
autoMemoryReclaim=gradual # 开启自动回收内存,可在 gradual, dropcache, disabled 之间选择
networkingMode=mirrored # 开启镜像网络
dnsTunneling=true # 开启 DNS Tunneling
firewall=true # 开启 Windows 防火墙
autoProxy=true # 开启自动同步代理
sparseVhd=true # 开启自动释放 WSL2 虚拟硬盘空间 -
重启 WSL 实例
在 Windows PowerShell 中输入
powershell
wsl --shutdown
在wsl环境里测试一下
powershell
curl -v www.google.com
即为配置成功