# WSL2安装配置

# **清理旧版 WSL 环境**

```powershell
# 查看已安装发行版，有输出说明存在旧版本
wsl --list --all

# 注销所有旧发行版
wsl --unregister docker-desktop

# 卸载系统组件
wsl --shutdown
dism.exe /online /disable-feature /featurename:Microsoft-Windows-Subsystem-Linux /norestart
dism.exe /online /disable-feature /featurename:VirtualMachinePlatform /norestart

# 软件卸载
# Windows Subsystem for Linux Update
# Ubuntu
# Docker Desktop
```


# 重新启用并安装 WSL2

```powershell
# 启用系统组件
dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart
dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart
# 重启电脑
shutdown /r /t 0

# 安装 WSL 内核
wsl --install --no-distribution

# 设置默认版本
wsl --set-default-version 2
```


# 安装 debian

```powershell
# 应用商店搜索后安装
# 进入系统
wsl
```


# 基础配置

```bash
# 换源
sudo sed -i "s@http://deb.debian.org@http://mirrors.huaweicloud.com@g" /etc/apt/sources.list
sudo sed -i "s@http://security.debian.org@http://mirrors.huaweicloud.com@g" /etc/apt/sources.list
sudo sed -i 's/main/main contrib non-free non-free-firmware/g' /etc/apt/sources.list
# 更新源
sudo apt update
# 安装常用工具
sudo apt install -y build-essential git curl wget vim btop net-tools
```