赞
踩
Windows Subsystem for Linux(WSL)
windows硬盘映射到wsl,默认路径为 /mnt
。
# 查看Linux发行版
wsl -l -v
或者
wsl --list --verbose
# 升级WSL
sudo do-release-upgrade -d
或者
wsl --update
# 停止正在运行的Linux子系统
wsl --shutdown
# 检查wsl状态
wsl --status
wsl --unregister DISTRO_NAME
通过重启windows达到重启wsl太耗费时间,但是wsl又不能通过reboot达到重启的目的。
管理员权限打开powershell ,然后执行下面命令。
关闭服务
net stop LxssManager
重启服务
net start LxssManager
现在 Ubuntu 的战略似乎都转向用 snapcraft 打包应用,很多软件在 apt 官方源内的版本都不是最新,甚至有的都不再提供 apt 安装方式。
snap 的使用需要依赖 systemd,而这个在 WSL2 上没有正常开启,导致我们在使用 snap 时会报错:
error: cannot communicate with server: Post http://localhost/v2/snaps/xxx: dial unix /run/snapd.socket: connect: no such file or directory
目前需要我们手动配置开启 systemd,即在 WSL 启动时执行 wsl-systemd 即可。
sudo vim /etc/wsl.conf
在这份配置文件中加上下面的配置:
[boot]
command="/usr/libexec/wsl-systemd"
重启WSL,即可正常使用snap。
方法一
vim ~/.bashrc
PATH=$PATH:/snap/bin
vim ~/.zshrc
PATH=$PATH:/snap/bin
source ~/.bashrc
source ~/.zshrc
方法二
echo 'export PATH=$PATH:/snap/bin\n' >> ~/.zshrc
echo 'export PATH=$PATH:/snap/bin\n' >> ~/.bashrc
source ~/.bashrc
source ~/.zshrc
待测试。
snap install too slow (kuricat.com)
snap list
yoyo@yoyo:~$ snap list
Name Version Rev Tracking Publisher Notes
core20 20220719 1587 latest/stable canonical✓ base
lxd 5.0.0-b0287c1 22923 5.0/stable/… canonical✓ -
snapd 2.56.2 16292 latest/stable canonical✓ snapd
WSL - GEDIT Unable to init server: Could not connect: Connection refused
下载安装 VcXsrv。
export DISPLAY=`grep nameserver /etc/resolv.conf | sed 's/nameserver //'`:0
或者
export DISPLAY=$(cat /etc/resolv.conf | grep nameserver | awk '{print $2}'):0
cd D:\360Downloads\VcXsrv
.\vcxsrv.exe -ac -terminate -lesspointer -multiwindow -clipboard -wgl
apt-get install
安装失败Bus error
解决办法:
重启wsl
Input/output error
-bash: /usr/bin/vim: Input/output error
解决办法:
重启wsl
liulinjun@LAPTOP-4DTD5D42:/etc/apt$ sudo apt-get install -y software-properties-common
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following additional packages will be installed:
python3-software-properties
The following packages will be upgraded:
python3-software-properties software-properties-common
2 upgraded, 0 newly installed, 0 to remove and 57 not upgraded.
Need to get 42.9 kB of archives.
After this operation, 0 B of additional disk space will be used.
Get:1 http://archive.ubuntu.com/ubuntu jammy-updates/main amd64 software-properties-common all 0.99.22.3 [14.1 kB]
Get:2 http://archive.ubuntu.com/ubuntu jammy-updates/main amd64 python3-software-properties all 0.99.22.3 [28.8 kB]
Fetched 42.9 kB in 2s (26.4 kB/s)
(Reading database ... 40394 files and directories currently installed.)
Preparing to unpack .../software-properties-common_0.99.22.3_all.deb ...
Unpacking software-properties-common (0.99.22.3) over (0.99.22.2) ...
Preparing to unpack .../python3-software-properties_0.99.22.3_all.deb ...
Unpacking python3-software-properties (0.99.22.3) over (0.99.22.2) ...
Setting up python3-software-properties (0.99.22.3) ...
Setting up software-properties-common (0.99.22.3) ...
Processing triggers for man-db (2.10.2-1) ...
Processing triggers for dbus (1.12.20-2ubuntu4) ...
Scanning processes...
Scanning processor microcode...
Scanning linux images...
Failed to retrieve available kernel versions.
Failed to check for processor microcode upgrades.
No services need to be restarted.
No containers need to be restarted.
No user sessions are running outdated binaries.
No VM guests are running outdated hypervisor (qemu) binaries on this host.
解决办法:
修改 needrestart 配置,找到 kernelhints 和 ucodehints 这两行,取消注释并将值改成 0:
sudo -e /etc/needrestart/needrestart.conf
$nrconf{kernelhints} = 0;
$nrconf{ucodehints} = 0;
yoyo@YOYO:~$ gedit test.txt
(gedit:1517): Gtk-WARNING **: 20:18:38.415: cannot open display:
解决方法:
参考上文,gedit可视化界面
使用WSL之前需要在BIOS中启动虚拟化,否则可能会出现问题。
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。