首页 > 解决方案 > 在 Visual Studio Code 中使用 Docker 和 WSL 2 进行开发 - -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

标签: dockervisual-studio-codewindows-subsystem-for-linux

解决方案


您的路径缺少来自 linux shell 的 Visual Studio 代码路径尝试

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

这只会暂时起作用。下次打开外壳时,您将不得不再次打开它。

使永久

$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


推荐阅读