Windows安装linux子系统
Windows安装linux子系统
- 什么是WSL
- 适用于 Linux 的 Windows 子系统可让开发人员按原样运行 GNU/Linux 环境 - 包括大多数命令行工具、实用工具和应用程序 - 且不会产生传统虚拟机或双启动设置开销。
- 什么是WSL2
- WSL 2 是适用于 Linux 的 Windows 子系统体系结构的一个新版本,它支持适用于 Linux 的 Windows 子系统在 Windows 上运行 ELF64 Linux 二进制文件。 它的主要目标是 提高文件系统性能,以及添加 完全的系统调用兼容性。
环境介绍
- 版本:Windows 10家庭版
- 版本号:20H2
- 操作系统内部版本:19042.1110
- Windows Terminal
ps:如何查看Windows内部版本号
- Windows徽标键+R,输入“winver”点击确定
WSL 2的安装
-
开启适用于Linux的Windows子系统,用管理员身份打开PowerShell
1
dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart
-
检查循行WSL的要求
- 对于 x64 系统:版本 1903 或更高版本,采用 内部版本 18362 或更高版本。
- 对于 ARM64 系统:版本 2004 或更高版本,采用 内部版本 19041 或更高版本。
- 低于 18362 的版本不支持 WSL 2。 使用 Windows Update 助手更新 Windows 版本。
-
启用虚拟机功能,用管理员身份打开PowerShell
1
dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart
-
重新启动计算机
-
下载Linux内核更新包
-
将WSL2设置为默认版本,用管理员身份打开PowerShell
1
wsl --set-default-version 2
-
在Microsoft Store中安装Linux发行版
-
进入Linux发行版,创建用户账户和密码
-
换源
-
查看版本号:
lsb_release -a
-
备份源配置文件
1
sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak
-
修改配置文件
1
2
3
4
5
6
7
8
9
10
11sudo vim /etc/apt/sources.list
# 内容如下
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-updates main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-updates main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-backports main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-backports main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-security main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-security main restricted universe multiverse
-
-
更新和升级包
1 | sudo apt update && sudo apt upgrade |
忘记密码怎么做
-
打开Powershell 进入WSL分发版的根目录
1
wsl -u root
-
使用命令更新密码
1
passwd <用户名>
参考资料
在 Windows 10 上安装 WSL | Microsoft Docs
Windows 终端 Powerline 设置 | Microsoft Docs
Windows Terminal + oh-my-posh模块美化官方教程集锦以及常见问题(问题收集中)_想追头头の疾风的博客-CSDN博客
Comment