【问题标题】:'zsh: command not found: ng' in Visual Studio Code's integrated terminal on Mac Catalina'zsh: command not found: ng' 在 Mac Catalina 上 Visual Studio Code 的集成终端中
【发布时间】:2021-04-09 05:34:38
【问题描述】:

较新的 Mac(在我的情况下为 Catalina OS)现在具有默认的 Z Shell aka zsh。使用 Mac zsh 终端窗口,我已经成功地全局安装了 Angular 11.0.5 并创建了一个项目。我正在使用nvm 0.32.2node 10.23.0

但是,在打开 Visual Studio Code 并在 VS Code 的 integrated terminal 中导航到我的项目时,我使用任何 ng 命令都会收到此错误消息,例如尝试生成组件:

zsh: command not found: ng

有谁知道如何正确设置 Visual Studio Code 的 integrated terminal 以正确识别使用 zsh 的 ng 命令?

我在https://stackoverflow.com/a/58584109/6647188 找到了一种可能的解决方法,但它使用了第三方工具,如果可能的话,我想避免使用。没有其他已知方法可以解决这个问题吗?

【问题讨论】:

    标签: angular macos visual-studio-code zsh macos-catalina


    【解决方案1】:
    • Sertings -> 功能 -> 终端

    • 点击“在settings.json中编辑”

    • 将此行(键值)添加到对象:

      "terminal.integrated.shell.osx": "/bin/zsh"
      
    • 关闭并重新启动 Visual Code。

    【讨论】:

    • 我将其标记为正确,因为这是需要的。但是,没有我做任何事情,这已经存在于设置中。我认为我出错的地方是我在全球范围内安装了Angular,但从未关闭并重新启动Visual Studio Code。我开了一个New Window,但这还不够。正如你所说,一个简单的关闭和重新启动,修复了一些事情。谢谢!
    • @VictorMartinezCalvo:你能解释一下,为什么这应该在这里有所帮助?实际上,OP从Visual Code调用的shell 已经是一个zsh,从他得到的错误消息的措辞中我们可以看出。
    • @user1934428 我可能应该编辑我的问题。该问题与使用 zshell 和 ng 命令的VS Code 无关。问题是(我相信)在全局安装 Angular 之后,我需要关闭并重新启动 VS Code 以使其识别 ng 命令。 @Victor Martinez Calvo 确实在他的回答中包含了这一步,所以我把它作为接受的答案。
    • 现在已弃用。新的推荐方式是"terminal.integrated.defaultProfile.osx": "zsh"
    【解决方案2】:

    如果这条线不适合你:

    "terminal.integrated.shell.osx": "/bin/zsh"
    

    然后尝试将“zsh”替换为“bash”,如下所示:

    "terminal.integrated.shell.osx": "/bin/bash"
    

    【讨论】:

      【解决方案3】:

      这是对我有用的设置

        "terminal.integrated.defaultProfile.osx": "zsh",
        "terminal.integrated.profiles.osx": {
          "tmux": {
            "icon": "terminal-tmux",
            "path": "tmux"
          },
          "zsh": {
            "path": "/bin/zsh"
          }
        },
      

      【讨论】:

        【解决方案4】:

        试试这个。为我工作

        alias ng="/Users/<user_name>/.npm-global/bin/ng"
        

        https://stackoverflow.com/a/48415572

        【讨论】:

          【解决方案5】:

          对于 1.62 的最新版本的 vscode,在我尝试使用其文档中的说明设置默认配置文件之前,没有任何效果:https://code.visualstudio.com/docs/editor/integrated-terminal#_terminal-profiles

          无需设置或命令,只需在 IDE 上单击几下即可。

          【讨论】:

            【解决方案6】:

            vscode 的新建议方式:

            This is deprecated, the new recommended way to configure your default shell is by creating a terminal profile 
            in `#terminal.integrated.profiles.osx#` and setting its profile name as the default 
            in `#terminal.integrated.defaultProfile.osx#`. 
            
            This will currently take priority over the new profiles settings but that will change in the future.
            

            【讨论】:

              猜你喜欢
              • 2022-12-17
              • 2018-04-07
              • 2021-06-28
              • 1970-01-01
              • 2019-12-11
              • 2018-03-23
              • 1970-01-01
              • 2019-07-07
              • 2020-06-14
              相关资源
              最近更新 更多