Windows 11 下 WSL Ubuntu 安装与配置实战
在 Windows 11 环境下使用 WSL(Windows Subsystem for Linux)可以无缝运行 Ubuntu,非常适合开发工作。下面分享一套完整的安装、配置及环境搭建流程。
启用虚拟化与子系统功能
首先确保系统支持。打开'启用或关闭 Windows 功能',勾选以下选项并重启:
- Virtual Machine Platform
- Hyper-V
- 适用于 Linux 的 Windows 子系统
安装 Ubuntu
更新终端后,直接运行安装命令。如果是首次使用,WSL 会自动下载相关组件,但网络慢时建议手动去官网获取离线包。
wsl --install -d Ubuntu-22.04
等待下载完成,按提示设置用户名和密码即可。
注:
wsl --install -d Ubuntu默认安装最新版,指定版本如Ubuntu-22.04可锁定发行版。
优化软件源
国内用户建议更换为阿里源,能显著提升 apt update 的速度。
编辑 /etc/apt/sources.list,清空原有内容并替换为以下内容:
deb https://mirrors.aliyun.com/ubuntu/ jammy main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ jammy main restricted universe multiverse
deb https://mirrors.aliyun.com/ubuntu/ jammy-security main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ jammy-security main restricted universe multiverse
deb https://mirrors.aliyun.com/ubuntu/ jammy-updates main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ jammy-updates main restricted universe multiverse
deb https://mirrors.aliyun.com/ubuntu/ jammy-backports main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ jammy-backports main restricted universe multiverse
保存后执行更新:
sudo apt update
sudo apt upgrade
常用操作与文件互传
文件管理
Windows 资源管理器左侧边栏会显示 Linux 文件系统入口,可直接拖拽文件。在 WSL 内部也可通过 /mnt/c/ 访问 Windows C 盘:
cp /mnt/c/path/to/file ~/destination/
mv /mnt/c/path/to/file ~/destination/
VS Code 远程连接
安装 WSL 扩展后,点击左下角绿色图标选择连接到 Ubuntu 实例,即可在 Windows 端享受原生 Linux 的开发体验。
[图:VS Code 连接界面]
常用命令速查
wsl --update:更新内核和组件,不自动升级发行版。wsl --list --online:查看可安装的发行版列表。


