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 了!
装完Ubuntu之后记得装build-essential,不然编译软件会缺工具。文章里提到了这点,很贴心。
This should be the official documentation. Clear, concise, and covers all the edge cases like kernel updates and mirror configuration.
作为开发小白,之前一直想用Linux又不敢装双系统。WSL简直是完美解决方案,谢谢这篇教程带我入门。
The verification commands at the end are helpful for making sure everything worked. wsl --list --verbose is my go-to check now.
代理配置那一段虽然简短但很关键,有时候apt连不上就是因为没有代理。加了环境变量之后一切都顺畅了。
I followed the WSL 2 steps exactly and now have Ubuntu running perfectly on Windows 11. No more dual boot headaches!
Windows Terminal确实比默认终端好用太多了,配色好看,还支持多标签页。强烈推荐大家装一个。
The WSL 2 kernel update link saved me. I kept getting that error and didn't know where to download the update. Much appreciated!
配置国内镜像源这个步骤太实用了,不然apt update慢得要命。换了阿里云源之后速度飞起,感谢提醒。
I love that you included both GUI and command-line methods. Some of us prefer the store, some want pure terminal. Great coverage!
强烈推荐用命令行安装方法,一条wsl --install搞定所有,比去商店找Ubuntu版本方便多了。新手用这个方法最省心。