WSL一些使用技巧

1.WSL安装

  • (1)开启选项
1
2
>> "打开或关闭Windows功能" -> "适用于Linux的Windows子系统"
>> "打开或关闭Windows功能" -> "虚拟机平台"
  • (2)设置WSL2
1
>> wsl --set-default-version 2
  • (3)安装Linux内核包
  • (4)安装Ubuntu:”Microsoft Store”安装,或命令行:
1
>> wsl --install -d Ubuntu-20.04

2.WSL恢复出厂设置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# 1.查看安装版本
>> wsl -l -v
NAME STATE VERSION
* Ubuntu-20.04 Running 2
docker-desktop Stopped 2
# 2.注销该发行版
>> wsl --unregister Ubuntu-20.04 # 名字换成你实际的
正在注销。
操作成功完成。
# 3.重新安装同名发行版
>> wsl --install -d Ubuntu-20.04
正在启动 Ubuntu 20.04 LTS...
Installing, this may take a few minutes...
Please create a default UNIX user account. The username does not need to match your Windows username.
For more information visit: https://aka.ms/wslusers
Enter new UNIX username: mirror
New password:
Retype new password:
passwd: password updated successfully
操作成功完成。
Installation successful!

3.WSL默认使用root身份登录

1
2
3
4
5
6
7
# 1.查看安装版本
>> wsl -l -v
NAME STATE VERSION
* Ubuntu-20.04 Running 2
docker-desktop Stopped 2
# 2.设置默认登录用户为root
>> ubuntu2004 config --default-user root

4.WSL卸载

  • (1)注销全部发行版
1
2
>> wsl --unregister Ubuntu
>> wsl --unregister Debian
  • (2)关闭Windows功能
1
2
3
4
"控制面板" -> “启动或关闭Windows功能” -> 取消勾选:
(1) 适用于Linux的Windows子系统;
(2) 虚拟机平台;
-> 重启电脑
  • (3)删除残留
1
C:\Users\Administrator\AppData\Local\Packages\CanonicalGroupLimited.Ubuntu20.04LTS_79rhkp1fndgsc

5.打开wsl文件路径

1
2
3
4
5
6
7
8
9
10
11
12
# 1.安装wslview
>> sudo apt install wslu
# 2.配置交互功能
>> sudo vim /etc/wsl.conf
# 添加如下内容
[interop]
enabled = true
appendWindowsPath = true
# 3.在powershell中重启wsl
>> wsl --shutdown
# 4.进入wsl,浏览路径
>> wslview .