当前位置:网站首页>还不会安装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 就算完成设置了。
边栏推荐
- File operation (detailed!)
- 【多线程】主线程等待子线程执行完毕在执行并获取执行结果的方式记录(有注解代码无坑)
- qt 仪表自定义控件
- 机械臂速成小指南(七):机械臂位姿的描述方法
- 多文件程序X32dbg动态调试
- php 二维、多维 数组打乱顺序,PHP_php打乱数组二维数组多维数组的简单实例,php中的shuffle函数只能打乱一维
- HOW TO ADD P-VALUES ONTO A GROUPED GGPLOT USING THE GGPUBR R PACKAGE
- Read the Flink source code and join Alibaba cloud Flink group..
- Log4j2
- 6. Introduce you to LED soft film screen. LED soft film screen size | price | installation | application
猜你喜欢

Pyqt5+opencv project practice: microcirculator pictures, video recording and manual comparison software (with source code)

机械臂速成小指南(七):机械臂位姿的描述方法

小程序链接生成

Larvel modify table fields

Some problems encountered in introducing lvgl into esp32 Arduino

Principe du contrat évolutif - delegatecall

Deep understanding of NN in pytorch Embedding

Power Spectral Density Estimates Using FFT---MATLAB

Filtre de profondeur de la série svo2

The computer screen is black for no reason, and the brightness cannot be adjusted.
随机推荐
Flesh-dect (media 2021) -- a viewpoint of material decomposition
Larvel modify table fields
PYQT5+openCV项目实战:微循环仪图片、视频记录和人工对比软件(附源码)
2022年遭“挤爆”的三款透明LED显示屏
Dynamic debugging of multi file program x32dbg
Repeat, tile and repeat in pytorch_ The difference between interleave
HOW TO CREATE A BEAUTIFUL INTERACTIVE HEATMAP IN R
Cmake cross compilation
How to Add P-Values onto Horizontal GGPLOTS
qt 仪表自定义控件
ORB-SLAM2不同线程间的数据共享与传递
C # method of obtaining a unique identification number (ID) based on the current time
MySql存储过程游标遍历结果集
HOW TO ADD P-VALUES TO GGPLOT FACETS
Cluster Analysis in R Simplified and Enhanced
Writing contract test cases based on hardhat
小程序链接生成
自然语言处理系列(二)——使用RNN搭建字符级语言模型
Esp32 audio frame esp-adf add key peripheral process code tracking
GGPlot Examples Best Reference