笔者今天了解到了WSL,简单介绍一下:
WSL(Windows Subsystem for Linux)是微软在Windows 10上推出的功能,它允许用户在Windows操作系统中运行本地的Linux发行版。这种功能使得开发人员和系统管理员可以在他们喜欢的Linux环境中使用工具和命令行界面,而无需离开Windows操作系统。
WSL通过在Windows操作系统上提供一个兼容的Linux内核接口来实现,这样用户就可以在Windows中运行原生的Linux二进制文件。它提供了一个完整的Linux系统用户态环境,包括常见的命令行工具、实用程序和应用程序,使得开发、测试和运行Linux应用程序在Windows环境中更加便捷。
WSL有两个主要版本:WSL 1和WSL 2。WSL 1是在Windows内核上通过适配器来运行Linux系统调用的子系统,而WSL 2则使用了一个真正的Linux内核,这使得WSL 2更加接近于原生的Linux体验,并且具有更好的性能和兼容性。
关于WSL的安装:超详细Windows10/Windows11 子系统(WSL2)安装Ubuntu20.04(带桌面环境)_wsl安装ubuntu20.04-优快云博客
在安装gnome桌面环境时候遇到一点问题:
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:
The following packages have unmet dependencies:
debianutils : Breaks: x11-common (< 1:7.7+23~) but 1:7.7+19ubuntu14 is to be installed
gdm3 : Depends: gnome-session-bin (>= 3.10) but it is not installable
Depends: gnome-shell (>= 3.19.92) but it is not installable
Recommends: xserver-xephyr but it is not installable
………………
xorg : Depends: xserver-xorg (>= 1:7.7+19ubuntu14) but it is not installable
xwayland : Depends: libgl1 but it is not installable
E: Unable to correct problems, you have held broken packages.
进行一些更新之后依旧没有解决问题,此时我退出WSL,再进时cmd报错:
nsenter: cannot open /proc/26/ns/time: No such file or directory
在参考文章
之后,总结解决方法如下:
#先运行
wsl -e bash --norc -m -p
#再运行
sudo nano /usr/sbin/enter-systemd-namespace
然后可以看到如下文本,里面的箭头的参数-a,是错误的
我们把他改成 -m,-p就可以
修改完之后,然后按Ctrl + O
保存,并按Ctrl + X
退出编辑模式。
之后可以正常启动wsl时
以后只需以管理员身份运行cmd,然后输入“bash”即可进入到Ubuntu系统下。
继续查阅资料后发现:我安装的是Ubuntu22.04版本,和上述安装教程版本不同,而安装gnome桌面环境时的报错是软件源问题导致的,故我替换了软件源:ubuntu | 镜像站使用帮助 | 清华大学开源软件镜像站 | Tsinghua Open Source Mirror
4.25更新:学长说不需要图形化界面,于是我就不下载gnome了嘿嘿。不过被安利了一个vscode插件WSL,这个插件支持在vscode下使用WSL。WSL+VSCode食用指南 - 知乎
搭配 VS Code Remote 远程开发扩展在 WSL 下开发 - 知乎
4/28更新:
vscode打开wsl时遇到问题
your 131072x1 screen size is bogus. expect trouble your 131072x1 screen size is bogus
解决方法如下:your 131072x1 screen size is bogus. expect trouble your 131072x1 screen size is bogus-优快云博客