在 Visual Studio 代码中使用 Docker 和 WSL 2 进行开发 - -sh: 代码:未找到

Develop with Docker and WSL 2 in Visual Studio Code - -sh: code: not found

我按照 https://docs.docker.com/docker-for-windows/wsl/ 上的教程进行操作。我已完成先决条件步骤:

并完成了第 1 步 - Open VSCode and install the Remote - WSL extension. This extension allows you to work with a remote server in the Linux distro and your IDE client still on Windows.

但是在第2步中,当我运行code .时,它抛出一个错误-sh: code: not found

您的路径缺少 Visual Studio 代码路径 尝试,从 linux shell

$export PATH="$PATH:/mnt/c/Users/{username}/AppData/Local/Programs/Microsoft VS Code"

这只会暂时起作用。下次打开 shell 时,您将不得不重新打开。

永久化

$vi ~/.profile

添加行

export PATH="$PATH:/mnt/c/Users/{username}/AppData/Local/Programs/Microsoft VS Code"

到文件末尾。 然后重新启动 shell 就可以了

https://code.visualstudio.com/docs/remote/troubleshooting#_fixing-problems-with-the-code-command-not-working

我无法使用 WSL 运行 命令来设置 PATH 变量,因此
我从 Microsoft 商店安装了 Linux 发行版(Ubuntu 20.04 LTS),如下所述:https://docs.microsoft.com/en-us/windows/wsl/install-win10#install-your-linux-distribution-of-choice 之后,我启动发行版,设置用户名和密码,通过输入“code”安装 vscode,导航到 mnt/... 目录并输入“code ..