当前位置:网站首页>还不会安装WSL 2?看这一篇文章就够了
还不会安装WSL 2?看这一篇文章就够了
2022-07-02 09:42:00 【raelum】
目录
一、前提条件
对于64位系统,若要安装WSL 2,需要满足OS内部版本≥18362。
按下 win + R
,然后输入 winver
来查看OS的内部版本:
可以看出我们的版本号满足要求,因此可以安装。
二、启用适用于 Linux 的 Windows 子系统
以管理员身份打开 Powershell,然后输入以下命令:
dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart
执行完后先不要关闭窗口。
三、启用虚拟机
继续在 Powershell 窗口中键入命令:
dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart
执行完后关闭窗口,重启计算机。
四、更新 Linux 内核
首先下载 适用于 x64 计算机的 WSL 2 Linux 内核更新包,然后双击进行安装。
如果系统提示你提供提升的权限,选择“是”以批准此安装。
五、将 WSL 2 设为默认版本
以管理员身份打开 Powershell,然后输入以下命令:
wsl --set-default-version 2
六、安装 Linux 发行版——Ubuntu
事实上 Microsoft Store 里就可以完成安装,但这里我们选择手动安装,因为手动安装的可操控性强。
一些 Linux 发行版及其下载地址:
Linux发行版 | Download |
---|---|
Ubuntu | https://aka.ms/wslubuntu |
Ubuntu 20.04 | https://aka.ms/wslubuntu2004 |
Ubuntu 18.04 | https://aka.ms/wsl-ubuntu-1804 |
Debian GNU/Linux | https://aka.ms/wsl-debian-gnulinux |
Kali Linux | https://aka.ms/wsl-kali-linux-new |
Fedora Remix for WSL | https://github.com/WhitewaterFoundry/WSLFedoraRemix/releases/ |
这里我们以 Ubuntu 20.04 为例,下载完成后,会得到一个名为 CanonicalGroupLimited.UbuntuonWindows_2004.2021.825.0.AppxBundle
的文件。从后缀名可以看出,它是与微软商店相关联的。
WSL 2的本质是虚拟机,相关的文件会存放在虚拟磁盘里(后缀名为 .vhdx
),该磁盘初始时就有一个多G,后续如果安装docker等软件的话C盘是吃不消的,因此我们需要将其安装在其他盘里(例如D盘)。
直接双击下载好的 AppxBundle
文件进行安装,它会默认安装到C盘。如下图,直接单击安装即可:

安装完成后,会弹出窗口让我们设置用户名和密码(注意密码不会回显),设置完成后关闭该窗口。
接下来进行迁移,我们以管理员身份打开 Powershell 窗口,然后输入
wsl -l --all -v
以查看已安装的发行版。
注意我们发行版的名称是 Ubuntu
而不是 Ubuntu-20.04
。
假设我们想要迁移至D盘,首先将发行版以 .tar
格式导出到D盘:
wsl --export Ubuntu d:\wsl-ubuntu.tar
然后注销当前的发行版:
wsl --unregister Ubuntu
之后重新导入并安装WSL 2在 D:\Ubuntu
下:
wsl --import Ubuntu d:\Ubuntu d:\wsl-ubuntu.tar --version 2
此外,还需要将默认登录用户的用户名设置为原来的用户名:
ubuntu config --default-user raelum
最后删除 .tar
文件
del d:\wsl-ubuntu.tar
七、安装 Windows Terminal
在 Microsoft Store 里搜索 Windows Terminal 并进行安装:

7.1 将 Ubuntu 设置为默认运行环境(可选)
将 Ubuntu 设置为默认运行环境的意思是,当我们启动 Windows Terminal 或在其中点击 “+” 号新建窗口时,会自动新建一个 Ubuntu 的窗口:

设置方法为,首先点击倒三角,在弹出的下拉列表中选择设置:

在弹出的窗口中再次点击齿轮按钮以打开 settings.json
文件:

我们在 profiles
的 list
下找到 Ubuntu 对应的 guid
:

再将 defaultProfile
后面的 guid
替换为该 guid
即可:

7.2 将启动目录设置为用户HOME目录
WSL 2 默认启动目录为 Windows 用户根目录:C:\Users\<Username>
,而不是 Linux 系统中用户的HOME目录,所以我们需要在 settings.json
里做一个更改。
事实上,只需要在 profiles
的 list
下找到 Ubuntu,然后添加一行:
"startingDirectory": "//wsl$/<Ubuntu_name>/home/<username>"
即可,其中 <Ubuntu_name>
是你的 Ubuntu 发行版的名称,最后保存 settings.json
就算完成设置了。
边栏推荐
- HOW TO ADD P-VALUES TO GGPLOT FACETS
- flutter 问题总结
- 【2022 ACTF-wp】
- uniapp uni-list-item @click,uniapp uni-list-item带参数跳转
- Power Spectral Density Estimates Using FFT---MATLAB
- php 根据经纬度查询距离
- to_ Bytes and from_ Bytes simple example
- Yygh-10-wechat payment
- Dynamic memory (advanced 4)
- Three transparent LED displays that were "crowded" in 2022
猜你喜欢
HOW TO ADD P-VALUES ONTO A GROUPED GGPLOT USING THE GGPUBR R PACKAGE
Data analysis - Matplotlib sample code
A sharp tool for exposing data inconsistencies -- a real-time verification system
[visual studio 2019] create and import cmake project
Principle of scalable contract delegatecall
Cluster Analysis in R Simplified and Enhanced
How to Visualize Missing Data in R using a Heatmap
【2022 ACTF-wp】
ESP32 Arduino 引入LVGL 碰到的一些问题
The selected cells in Excel form have the selection effect of cross shading
随机推荐
Dynamic debugging of multi file program x32dbg
vant tabs组件选中第一个下划线位置异常
GGHIGHLIGHT: EASY WAY TO HIGHLIGHT A GGPLOT IN R
Implementation of address book (file version)
Depth filter of SvO2 series
The position of the first underline selected by the vant tabs component is abnormal
What week is a date obtained by QT
预言机链上链下调研
机械臂速成小指南(七):机械臂位姿的描述方法
YYGH-BUG-05
GGPLOT: HOW TO DISPLAY THE LAST VALUE OF EACH LINE AS LABEL
XSS labs master shooting range environment construction and 1-6 problem solving ideas
[visual studio 2019] create MFC desktop program (install MFC development components | create MFC application | edit MFC application window | add click event for button | Modify button text | open appl
基于Hardhat和Openzeppelin开发可升级合约(一)
Pytorch builds LSTM to realize clothing classification (fashionmnist)
uniapp uni-list-item @click,uniapp uni-list-item带参数跳转
What is the relationship between digital transformation of manufacturing industry and lean production
Log4j2
Industry analysis
Log4j2