✅ 一、必须做(强烈建议,属于基础设施)
1️⃣ 设置默认用户(避免每次 root)
bash
whoami
如果是 root,建议:
bash
adduser slt
usermod -aG sudo slt
然后在 Windows 里设置:
cmd
wsl -d Ubuntu-24.04 -u slt
或通过 /etc/wsl.conf(推荐):
bash
sudo nano /etc/wsl.conf
写入:
ini
[user]
default=slt
然后:
cmd
wsl --shutdown
2️⃣ 更换国内 apt 源(速度提升 10 倍)
以 清华源 为例(Ubuntu 24.04):
bash
sudo sed -i 's|http://archive.ubuntu.com|https://mirrors.tuna.tsinghua.edu.cn|g' /etc/apt/sources.list
sudo sed -i 's|http://security.ubuntu.com|https://mirrors.tuna.tsinghua.edu.cn|g' /etc/apt/sources.list
sudo apt update && sudo apt upgrade -y
3️⃣ 基础工具包(几乎必装)
bash
sudo apt install -y \
build-essential \
curl wget git unzip zip \
ca-certificates \
net-tools iputils-ping \
htop tree lsof
🚀 二、强烈推荐(开发 / 运维 / 学习)
4️⃣ Windows ↔ WSL 文件互通优化
访问 Windows 盘:
bash
cd /mnt/e
禁止在 /mnt/c 做大量编译(性能差)
建议:
bash
~/workspace
在 Linux 文件系统内开发。
5️⃣ 设置 WSL 资源限制(非常重要)
在 Windows 创建:
C:\Users\<你>\.wslconfig
内容示例:
ini
[wsl2]
memory=8GB
processors=6
swap=0
然后:
cmd
wsl --shutdown
6️⃣ Docker(WSL 原生方式,推荐)
安装 Docker Engine(非 Docker Desktop)
bash
curl -fsSL https://get.docker.com | sudo bash
sudo usermod -aG docker $USER
重启 WSL:
cmd
wsl --shutdown
测试:
bash
docker run hello-world
🧠 三、进阶配置(你这个用户非常适合)
7️⃣ Python / Conda / AI 环境
Python(系统级)
bash
sudo apt install -y python3 python3-pip python3-venv
Miniconda(推荐)
bash
wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh
bash Miniconda3-latest-Linux-x86_64.sh
8️⃣ SSH / Git 配置
bash
ssh-keygen -t ed25519
cat ~/.ssh/id_ed25519.pub
Git 基础配置:
bash
git config --global user.name "yourname"
git config --global user.email "you@example.com"
9️⃣ 网络调优(WSL 常见问题)
bash
sudo sysctl -w net.ipv4.ip_forward=1
必要时:
bash
sudo nano /etc/resolv.conf
🔐 四、安全 & 稳定性(长期使用)
🔟 定期备份(强烈建议)
cmd
wsl --export Ubuntu-24.04 E:\vm\backup\ubuntu24.04_$(date +%F).tar
11️⃣ 快照级"模板化"(高手玩法)
- 配置好一个"干净 Ubuntu"
- export 成模板
- 多个项目 import 使用
🎯 给你一个「建议优先顺序」
如果你时间有限,按这个来:
- 默认用户
- apt 国内源
- 基础工具
.wslconfig- Docker
- Python / Conda