wsl2默认不启用systemd,无法使用systemctl
编辑 /etc/wsl.conf
[boot]
systemd=true
WSL2内置终端卡顿的罪魁祸首就是WSL2默认将Windows的环境变量添加到了WSL里,在Linux终端遍历环境变量的时候会遍历到Windows的环境变量,问题就出在了这里,因为WSL2访问Windows I/O 的性能极低,就导致终端遍历的速度很慢,出现滞后(这种滞后一般出现在加装了高亮提示插件的ZSH上,因为高亮提示插件会不停的遍历环境变量)
直接禁用WSL2访问Windows的环境变量即可
编辑/etc/wsl.conf
[interop]
appendWindowsPath=false
编辑 /etc/profile
文件,在末尾添加上
export PATH="$PATH:/mnt/c/Users/Mov/AppData/Local/Microsoft/WindowsApps"
export PATH="$PATH:/mnt/c/Program Files/Docker/Docker/resources/bin"
export PATH="$PATH:/mnt/c/Windows"
export PATH="$PATH:/mnt/d/Program Files/Microsoft VS Code/bin"
重启WSL2即可
WSL2终端卡顿滞后的优化方法以及WSL2启用systemd – FGP_Blog (goblog.top)