wsl2环境的搭建

安装WSL

        WSL Windows官方页面:安装 WSL | Microsoft Learn

  • 系统要求版本:我的电脑->属性可以查看系统版本,采用内部版本 18362 或更高版本
  • 以管理员权限运行 powershell
  • 启用Windows10子系统功能,再打开的powershell窗口中输入如下命令
dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart
  • 启用虚拟机平台功能,再打开的powershell窗口中输入如下命令
dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart
  • 重启电脑
  • 再次打开powershell
  • 安装WSL,以管理员权限运行 powershell
wsl --update
  • 配置为wsl2,注意当你用管理权限打开安装时你也必须用管理员权限开的任务栏的ubuntu系统,请注意权限问题,这里建议下面操作不要用管理员权限
# 设置默认的版本为 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

配置Linux系统

至此WSL的系统已经完成安装,但是还不能满足需求,比如UI,此篇主要介绍如何配置环境并能运用UI界面

由于在任务栏打开的ubuntu20.04只是一个终端,并不带X11-forwarding (remote display is forwarded through SSH),所以并不能运行带UI的程序

  • 配置ssh
sudo apt-get update
sudo apt-get install openssh-server openssh-client net-tools fonts-noto-cjk
  • 修改ssh的配置文件

在/etc/ssh/sshd_config文件中,将PasswordAuthentication设置为 yes,或直接在 PasswordAuthentication参数前添加井号#

  • 启动服务
sudo /etc/init.d/ssh restart
  • 安装windows mobaxterm工具,并用ssh登入即可,当然你的PC的IP需要满足网络安全的IP要求
https://mobaxterm.mobatek.net/download.html 
  • 这个时候你就可以用check等UI工具了,ubuntu是共享你windows的网卡和IP的
  • 还可以将ubuntu的filesystem映射出来以一个盘符的形式存在,打开我的电脑,在最左下角的网络系统映射出来

三. 调试环境配置

到这里后,WSL2已经配置好了,在powershell输入wsl或者在任务栏打开ubuntu20.04都可以进入linux系统

vscode官方配置wsl编译环境为Developing in the Windows Subsystem for Linux with Visual Studio Code,以下为详细流程

  • 在windows下安装好vscode
  • 进入linux系统,到你想要打开的代码目录,输入
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.

  • 这个时候你会看到一个vscode产生,并产生安装通知,请安装

VS Code will now continue to configure itself in WSL and keep you up to date as it makes progress.

  • 上面的通知都安装OK后,你将在左下角看到如下图标,这个时候你就可以正常使用

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.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Tango Tang

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值