WSL开发环境

1. 安装和配置 WSL

WSL 全称 Windows Subsystem for Linux

Windows Powershell 中执行:

1
2
3
4
5
6
7
8
9
10
11
12
Add-Content -Path $HOME\.wslconfig -Value @'
[wsl2]
networkingMode=mirrored
defaultVhdSize=107374182400
'@

# install wsl, run as administrator
wsl --install

# set firewall, run as Administrator
# ref: https://learn.microsoft.com/en-us/windows/security/operating-system-security/network-security/windows-firewall/hyper-v-firewall
Set-NetFirewallHyperVVMSetting -Name '{40E0AC32-46A5-438A-A0B2-2B479E8F2E90}' -DefaultInboundAction Allow

WSL 中执行:

1
2
3
4
5
6
7
8
9
10
11
12
13
# backup ubuntu apt source
sudo cp /etc/apt/sources.list.d/ubuntu.sources{,.bak}
# config ubuntu apt source mirror
sudo sed -i 's@//.*archive.ubuntu.com@//mirrors.aliyun.com@g' /etc/apt/sources.list.d/ubuntu.sources
sudo sed -i 's@//.*security.ubuntu.com@//mirrors.aliyun.com@g' /etc/apt/sources.list.d/ubuntu.sources
# update apt and install aptitude
sudo apt update && sudo apt install aptitude

# config git
git config --global credential.helper "/mnt/c/Program\ Files/Git/mingw64/bin/git-credential-manager.exe"
git config --global core.sshcommand "ssh.exe"
git config --global user.name "Michael Ding"
git config --global user.email "yandy.ding@gmail.com"

2. WSL 管理

Windows Powershell 中

1
2
3
4
# reduce wsl virtual disk file
# run as administrator
cd $HOME\AppData\Local\Packages\<WSL Distro>\LocalState
Optimize-VHD -Path .\ext4.vhdx -Mode full

3. Language

作者

Michael Ding

发布于

2024-10-06

更新于

2024-10-06

许可协议