WSL Windows官方页面:安装 WSL | Microsoft Learn
dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart
dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart
wsl --update
- # 设置默认的版本为 wsl2
- wsl --set-default-version 2
-
- #查看支持的linux子系统
- wsl -l -o
-
- # 安装linux子系统, 期间需要创建账户和密码
- wsl --install -d Ubuntu-20.04
-
- #检查安装的linux版本
- wsl -l -v
- #输出如下信息表示wsl2启动ok
- #NAME STATE VERSION
- #* Ubuntu-20.04 Running 2
至此WSL的系统已经完成安装,但是还不能满足需求,比如UI,此篇主要介绍如何配置环境并能运用UI界面
由于在任务栏打开的ubuntu20.04只是一个终端,并不带X11-forwarding (remote display is forwarded through SSH),所以并不能运行带UI的程序
- sudo apt-get update
- sudo apt-get install openssh-server openssh-client net-tools fonts-noto-cjk
在/etc/ssh/sshd_config文件中,将PasswordAuthentication设置为 yes,或直接在 PasswordAuthentication参数前添加井号#
sudo /etc/init.d/ssh restart
https://mobaxterm.mobatek.net/download.html
到这里后,WSL2已经配置好了,在powershell输入wsl或者在任务栏打开ubuntu20.04都可以进入linux系统
vscode官方配置wsl编译环境为Developing in the Windows Subsystem for Linux with Visual Studio Code,以下为详细流程
code .
** in the terminal. When doing this for the first time, you should see VS Code fetching components needed to run in WSL. This should only take a short while, and is only needed once.
Note: If this command does not work, you may need to restart your terminal or you may not have added VS Code to your path when it was installed.
VS Code will now continue to configure itself in WSL and keep you up to date as it makes progress.
That's it! Any VS Code operations you perform in this window will be executed in the WSL environment, everything from editing and file operations, to debugging, using terminals, and more.