【问题标题】:Code command terminal interface on macOS of Visual Studio Code not works after restart systemVisual Studio Code的macOS上的代码命令终端界面在重新启动系统后不起作用
【发布时间】:2018-04-09 15:11:24
【问题描述】:

我使用终端 code file.txt 上的命令用 Visual Studio Code 打开文件,但是当我重新启动系统时,命令停止工作。我需要打开 Visual Studio Code,并重新配置路径以使用 code 命令行界面。 我该如何解决这个问题?我正在使用 macOS HighSierra。

在我重新启动系统后,命令显然消失了。

-bash: code: command not found

【问题讨论】:

  • 在终端运行一次ln -fs "/Applications/Visual Studio Code.app/Contents/Resources/app/bin/code" /usr/local/bin/code,看看是否能解决问题。另外,当您说重新启动后它不起作用。这是否意味着命令错误或命令实际上没有打开文件
  • 该命令在我重新启动系统之前有效。
  • 我确实执行了你的命令,但没有解决。
  • 你是怎么安装vscode的?通常还是通过brew? Command not found 是总是重启时出现的错误
  • 通常情况下,是的,我已经测试过几次,关键字code file.txt stop 总是有效。

标签: macos command-line visual-studio-code


【解决方案1】:

所以你的问题可能与你安装VSCode的方式有关

我会在下面运行以安装相同的

brew cask install visual-studio-code

如果您不想使用 brew,那么我会从以下链接下载该应用程序

https://code.visualstudio.com/docs/?dv=osx

解压后将其移动到finder中的Applications文件夹。

MacOS Gatekeeper 可能会在每次重新启动后干扰您的应用程序的位置。这意味着symlink 每次重新启动都会失效,因此会出现问题

如果重启后问题仍然存在,您希望将 VScode 排除在 Gatekeeper 之外

spctl --add "/Applications/Visual Studio Code.app"

【讨论】:

    【解决方案2】:

    尝试再次重复official documentation 中描述的内容。


    使用以下命令检查 Visual Studio Code 是否安装在正确的文件夹中:ls -l /usr/local/bin/code

    你可以通过在 bash 中运行命令which codewhere code 找到正确的路径。

    如果命令返回这样的路径:/usr/local/bin/code -> /private/var/folders/xf/vnnm636d0k92w3sc7lm95w040000gn/T/AppTranslocation/3815E4B6-43DB-0F8E-AAB9-EDE3AC7F67CC/d/Visual Studio Code.app/Contents/Resources/app/bin/code /usr/local/bin,则表示程序安装在临时文件夹中。

    路径必须是:/Applications/Visual Studio Code.app/Contents/Resources/app/bin/code

    如果程序安装在临时文件夹中,则可能会导致此问题。

    Visual Studio Code.app 拖到Applications 文件夹并重复 来自official documentation的说明。

    如果上述操作后仍然无法运行,并且程序没有安装在临时文件夹中,建议检查~/.bash_profile~/.bash_profile 中的bash 设置。


    附言

    另外,如果以上方法都不起作用,您可以尝试以下方法:sudo ln -fs "/Applications/Visual Studio Code.app/Contents/Resources/app/bin/code" "/usr/local/bin/"

    【讨论】:

    • 我试过这个,不行。当我重新启动时,没有更多的工作。
    • which code返回的路径是什么?可能 Visual Studio Code 安装在一个临时文件夹中。
    • 好吧,我确实下载了VS,安装了程序,配置了路径。所以,code file.txt 有效。我重新启动系统,code file.txt 返回:-bash: code: command not found
    • 你能写出下一个命令返回的ls -l /usr/local/bin/code吗?这是检查程序是否安装在临时文件夹中所必需的。
    • Visual Studio Code.app 拖到Applications 文件夹并重复official documentation 中的说明。现在 Visual Studio Code 安装在一个临时文件夹中,因此重启后code 命令不可用。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-11-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-05-26
    相关资源
    最近更新 更多