WSL 安装 Ubuntu 教程
WSL (Windows Subsystem for Linux) 允许在 Windows 上直接运行 Linux 环境。以下是详细安装步骤:
一、系统要求
- Windows 10 版本 2004 及以上(内部版本 19041 及以上)或 Windows 11
- 64 位系统
二、安装步骤
方法1:图形界面安装(推荐)
以管理员身份打开 PowerShell,运行以下命令启用 WSL:
dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart启用虚拟机平台(WSL 2 需要):
dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart- 重启电脑
将 WSL 2 设为默认版本:
wsl --set-default-version 2- 打开 Microsoft Store,搜索 "Ubuntu",选择版本(推荐 Ubuntu 22.04 LTS 或 Ubuntu 24.04 LTS),点击"安装"
方法2:命令行安装
在 PowerShell(管理员)中直接运行:
# 安装 WSL 并默认安装 Ubuntu
wsl --install
# 或指定安装特定版本
wsl --install -d Ubuntu-22.04三、首次启动配置
- 安装完成后,在开始菜单找到 Ubuntu 并启动
等待初始化完成,系统会提示创建用户名和密码:
Enter new UNIX username: 你的用户名 New password: 设置密码 Retype password: 确认密码
四、验证安装
# 查看 WSL 版本
wsl --status
# 查看已安装的发行版
wsl --list --verbose五、常见问题处理
1. WSL 2 内核更新
如果提示需要更新内核,下载并安装:
2. 切换 WSL 版本
# 设置默认版本为 WSL 2
wsl --set-default-version 2
# 将特定发行版切换为 WSL 2
wsl --set-version Ubuntu-22.04 23. 配置代理(如果需要)
在 Ubuntu 中编辑 ~/.bashrc,添加:
export http_proxy="http://127.0.0.1:7890"
export https_proxy="http://127.0.0.1:7890"六、可选配置
1. 安装 Windows Terminal
从 Microsoft Store 安装 Windows Terminal,获得更好的终端体验
2. 配置国内镜像源(加速包管理)
sudo sed -i 's@archive.ubuntu.com@mirrors.aliyun.com@g' /etc/apt/sources.list
sudo apt update && sudo apt upgrade3. 安装常用开发工具
sudo apt install build-essential git curl wget vim安装完成后,你就可以像使用原生 Linux 一样使用 Ubuntu 了!
I appreciate that you included the option to use Microsoft Store. Some people prefer GUI installation and that's totally valid.
建议把WSL 2设为默认后,再装Ubuntu,这样装好的就是WSL 2版本。教程顺序安排得很合理。
The step-by-step approach with separate PowerShell commands gives you control over each part of the installation. Great for learning.
wsl --status这个命令之前都不知道,现在可以方便查看WSL版本和状态了。这些小技巧很实用。
This is the most straightforward WSL guide I've found. No fluff, just working commands and clear explanations.