当我尝试从WSL执行代码时,像这样:
cmd.exe
wsl code .
我收到以下错误:
/bin/bash: code: command not found
但是,如果我执行相同的命令但首先以管理员身份运行cmd.exe,则vscode将按预期方式打开。
问题是,当我以非管理员身份运行时,为什么无法识别“代码”,我该如何解决?
其他信息: WSL2版本41959 vscode版本1.38 vscode远程WSL扩展版本0.39.5
答案 0 :(得分:6)
wsl --list --version
显示为wsl 2
wsl
chmod u+x vscode_dir/code.exe
chmod u+x vscode_dir/bin/code
ln -s vscode_dir/bin/code code
mv code ~/.local/bin
.bashrc
,如下添加一行:export PATH="$HOME/.local/bin:$PATH"
source .bashrc
或重新启动终端。然后,您可以在wsl2-ubuntu环境或VSCode终端中愉快地播放代码。
答案 1 :(得分:0)
如@Biswapriyo所述,这是一个开放的bug,WSL无法访问Windows C驱动器。 帮助我的解决方法是像这样重新启动WSL:
wsl --shutdown
wsl
答案 2 :(得分:0)
就我而言,我使用的是 Debian 并且 echo %PATH% 没有输出任何内容。
我使用了来自 resolved github issue
的建议解决方案的第二部分App
选项 1:
For Debian, /etc/profile contributed to this problem.
Here is the path definition in /etc/profile
if [ "`id -u`" -eq 0 ]; then
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
else
PATH="/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games"
fi
选项 2:
You can delete above lines, then wsl --shutdown to restart Debian.