当前位置:网站首页>还不会安装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
就算完成设置了。
边栏推荐
- Natural language processing series (II) -- building character level language model using RNN
- Small guide for rapid formation of manipulator (VII): description method of position and posture of manipulator
- QT获取某个日期是第几周
- 可升级合约的原理-DelegateCall
- easyExcel和lombok注解以及swagger常用注解
- 数据分析 - matplotlib示例代码
- 深入理解PyTorch中的nn.Embedding
- Develop scalable contracts based on hardhat and openzeppelin (II)
- deepTools对ChIP-seq数据可视化
- Cmake cross compilation
猜你喜欢
YYGH-9-预约下单
深入理解PyTorch中的nn.Embedding
可升级合约的原理-DelegateCall
ESP32存储配网信息+LED显示配网状态+按键清除配网信息(附源码)
Seriation in R: How to Optimally Order Objects in a Data Matrice
Seriation in R: How to Optimally Order Objects in a Data Matrice
HOW TO ADD P-VALUES TO GGPLOT FACETS
PyTorch nn.RNN 参数全解析
H5, add a mask layer to the page, which is similar to clicking the upper right corner to open it in the browser
A sharp tool for exposing data inconsistencies -- a real-time verification system
随机推荐
Mish-撼动深度学习ReLU激活函数的新继任者
deepTools对ChIP-seq数据可视化
K-Means Clustering Visualization in R: Step By Step Guide
Pyqt5+opencv project practice: microcirculator pictures, video recording and manual comparison software (with source code)
可昇級合約的原理-DelegateCall
Read the Flink source code and join Alibaba cloud Flink group..
Seriation in R: How to Optimally Order Objects in a Data Matrice
HOW TO ADD P-VALUES TO GGPLOT FACETS
Writing contract test cases based on hardhat
YYGH-9-预约下单
预言机链上链下调研
GGPlot Examples Best Reference
Natural language processing series (II) -- building character level language model using RNN
How to Create a Nice Box and Whisker Plot in R
Pytorch builds LSTM to realize clothing classification (fashionmnist)
HOW TO CREATE A BEAUTIFUL INTERACTIVE HEATMAP IN R
Homer forecast motif
Mmrotate rotation target detection framework usage record
This article takes you to understand the operation of vim
PHP 2D and multidimensional arrays are out of order, PHP_ PHP scrambles a simple example of a two-dimensional array and a multi-dimensional array. The shuffle function in PHP can only scramble one-dim