来了!WSL 2 GUI 原生支持!

参阅文献

  • https://docs.microsoft.com/zh-cn/windows/wsl/tutorials/gui-apps

先决条件

要在 Windows 上体验 WSL 2 GUI 应用,需要满足以下条件:

  • Windows 10 预览版 21362+
  • 安装适用于 vGPU 的驱动程序

升级到 Windows 10 预览版 21362+

通过 WSL 对 Linux GUI 应用的支持将在 Windows 的下一个主要版本中推出。 若要访问 Windows 预览版并尝试立即运行 Linux GUI 应用,需要加入 Windows 预览体验计划,然后从开发通道Windows 10预览体验成员预览版。

打开 设置 -> 更新和安全 -> Windows 预览体验计划
![image.png](https://img-blog.csdnimg.cn/img_convert/38baa765e5fbcac22bdce70bae2ceb60.png#align=left&display=inline&height=182&margin=[object Object]&name=image.png&originHeight=363&originWidth=561&size=169203&status=done&style=none&width=280.5)
![image.png](https://img-blog.csdnimg.cn/img_convert/e66567dc6008f04848eaa751f3fe8a74.png#align=left&display=inline&height=502&margin=[object Object]&name=image.png&originHeight=1004&originWidth=1288&size=70824&status=done&style=none&width=644)
![image.png](https://img-blog.csdnimg.cn/img_convert/49c8b071152a0367f6065cdb31f5ab67.png#align=left&display=inline&height=502&margin=[object Object]&name=image.png&originHeight=1004&originWidth=1288&size=367872&status=done&style=none&width=644)
在加入到Windows预览体验计划后,按提示重启电脑,之后在 Windows 更新中点击检查更新,之后等待更新完成,重启系统就可以升级到最新的预览版系统了
![image.png](https://img-blog.csdnimg.cn/img_convert/fa892991ac9eb481a8c8e2b7ff395bbe.png#align=left&display=inline&height=51&margin=[object Object]&name=image.png&originHeight=101&originWidth=412&size=55768&status=done&style=none&width=206)

安装适用于 vGPU 的驱动程序

若要运行 Linux GUI 应用,应首先安装与以下系统匹配的预览驱动程序。 这样,就可以将虚拟 GPU (vGPU) ,以便可以从硬件加速 OpenGL 呈现中获益。

适用于 Intel 的 WSL GPU 驱动程序:https://downloadcenter.intel.com/download/29526
适用于 AMD 的 WSL GPU 驱动程序:https://www.amd.com/en/support/kb/release-notes/rn-rad-win-wsl-support
适用于 NVIDIA 的 WSL GPU 驱动程序: https://developer.nvidia.com/cuda/wsl

安装 WSL

如果尚未执行 安装 WSL的步骤,可以使用新的简化安装命令。
在开始菜单中搜索 PowerShell 并以管理员身份运行 PowerShell
![image.png](https://img-blog.csdnimg.cn/img_convert/2a0c5eb06b0359d290b3be864c241616.png#align=left&display=inline&height=426&margin=[object Object]&name=image.png&originHeight=851&originWidth=1043&size=204396&status=done&style=none&width=521.5)
PowerShell 中运行:

wsl --install -d Ubuntu # 安装 WSL 并运行 Ubuntu 分发

![image.png](https://img-blog.csdnimg.cn/img_convert/3469c46a7f3cfaa7171093c76d3cb757.png#align=left&display=inline&height=207&margin=[object Object]&name=image.png&originHeight=413&originWidth=856&size=46274&status=done&style=none&width=428)
重启电脑后将继续安装,并按要求输入用户名和密码

从现有的 WSL 更新

如果已经在计算机上安装了 WSL,则可以通过从提升的命令提示符运行 update 命令,更新到包含 Linux GUI 支持的更新版本。

  1. 选择 " 开始",键入 " PowerShell",右键单击 " Windows PowerShell",然后选择 " 以管理员身份运行"。
  2. 输入 WSL update 命令:
wsl --update
  1. 你将需要重新启动 WSL,以使更新生效。 可以通过在 PowerShell 中运行 shutdown 命令来重新启动 WSL。
wsl --shutdown

运行 Linux GUI 应用

安装 Chrome 浏览器

wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
sudo apt-get update
sudo apt install ./google-chrome-stable_current_amd64.deb

运行 Chrome,你可以直接在 Windows 开始菜单中启动 Chrome,也可以直接运行以下命令,第一次启动的时候会比较慢,需要等待一下

google-chrome

![image.png](https://img-blog.csdnimg.cn/img_convert/6eb2f1620b7f9e9919014d4e8f30d2a3.png#align=left&display=inline&height=425&margin=[object Object]&name=image.png&originHeight=850&originWidth=807&size=631791&status=done&style=none&width=403.5)
![image.png](https://img-blog.csdnimg.cn/img_convert/fe5a5eb78858cc404536423605d568e0.png#align=left&display=inline&height=89&margin=[object Object]&name=image.png&originHeight=177&originWidth=505&size=12170&status=done&style=none&width=252.5)
![image.png](https://img-blog.csdnimg.cn/img_convert/6931ca0e7ab32138d0fff10a7c77f271.png#align=left&display=inline&height=477&margin=[object Object]&name=image.png&originHeight=953&originWidth=1072&size=55946&status=done&style=none&width=536)

安装中文字体

sudo apt install fonts-wqy-microhei ttf-wqy-zenhei	# 安装中文字体
fc-list :lang=zh-cn	# 查看已安装的中文字体

安装中文输入法

生成中文环境

sudo locale-gen zh_CN.UTF-8

安装输入法

sudo apt install fcitx fcitx-googlepinyin

配置环境变量,编辑 /etc/profile 文件

...
+ export LANG=zh_CN.UTF-8
+ export GTK_IM_MODULE=fcitx
+ export QT_IM_MODULE=fcitx
+ export XMODIFIERS=\@im=fcitx

刷新使文件生效

source /etc/profile

运行输入法

fcitx

查看效果
打开Chrome浏览器,然后按 Ctrl+空格键 切换输入法

google-chrome

![image.png](https://img-blog.csdnimg.cn/img_convert/2c53ece0a49ef42353865f7f1454d1df.png#align=left&display=inline&height=122&margin=[object Object]&name=image.png&originHeight=243&originWidth=1265&size=33279&status=done&style=none&width=632.5)
![image.png](https://img-blog.csdnimg.cn/img_convert/9fc0b1332bfc3a156456c0200ea08805.png#align=left&display=inline&height=230&margin=[object Object]&name=image.png&originHeight=459&originWidth=1265&size=94925&status=done&style=none&width=632.5)
开机自启动输入法
编辑文件 /etc/bash.bashrc ,加入如下内容

...
+ fcitx

你可能感兴趣的:(博客专栏,linux,windows)