wsl ubuntu的基础配置

✅ 一、必须做(强烈建议,属于基础设施)

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 使用

🎯 给你一个「建议优先顺序」

如果你时间有限,按这个来:

  1. 默认用户
  2. apt 国内源
  3. 基础工具
  4. .wslconfig
  5. Docker
  6. Python / Conda

相关推荐
衫水1 天前
ubuntu系统如何检查和安装以及运行redis
redis·ubuntu·bootstrap
苏宸啊1 天前
Linux权限
linux·运维·服务器
xqhoj1 天前
Linux——make、makefile
linux·运维·服务器
张童瑶1 天前
Linux 在线安装编译Python3.11
linux·运维·python3.11
Shi_haoliu1 天前
SolidTime 在 Rocky Linux 9.5 上的完整部署流程
linux·运维·nginx·postgresql·vue·php·laravel
Lkygo1 天前
LlamaIndex使用指南
linux·开发语言·python·llama
qq_254617771 天前
nslookup 这个命令解析dns,和系统接口gethostbyname解析区别在哪?
linux·网络
HIT_Weston1 天前
100、【Ubuntu】【Hugo】搭建私人博客:元信息&翻译(一)
linux·运维·ubuntu
Mr. Cao code1 天前
Docker匿名数据卷实战指南
运维·ubuntu·docker·容器
自由的好好干活1 天前
UBI镜像文件打包与编辑
linux·嵌入式硬件