酿造安装nvm。 nvm:找不到命令

Brew install nvm. nvm: command not found

用 brew 安装 nvm 和 运行 nvm 后,显示 nvm: command not found

如何让命令执行?

使用 brew 安装 nvm 有两个步骤。

首先使用brew安装应用:

brew install nvm

然后查看 brew 信息的“注意事项”部分,看看您还需要做什么:

brew info nvm

您可能会看到类似的内容(这可能会改变!):

You should create NVM's working directory if it doesn't exist:

  mkdir ~/.nvm

Add the following to ~/.bash_profile or your desired shell
configuration file:

  export NVM_DIR="$HOME/.nvm"
  . "/usr/local/opt/nvm/nvm.sh"

如果您没有 ~/.bash_profile 文件,那么您可以简单地创建一个。

确保重新启动终端,然后再尝试运行 nvm 命令。

From the docs:

Your system may not have a [.bash_profile file] where the command is set up. Simply create one with touch ~/.bash_profile and run the install script again

you might need to restart your terminal instance. Try opening a new tab/window in your terminal and retry.

重新启动对我有用...为什么不能让所有错误都变得如此简单?!!

我在 运行 npm install

之后遇到了同样的问题

以下解决方案对我有用:

  1. 运行 brew doctor 查找 NPM 损坏的符号链接

  2. 运行 brew cleanup 清理它们

我遵循了@user3207874 的回答,但它仍然不适合我。在这些步骤之后我必须 运行 这个命令:

source $(brew --prefix nvm)/nvm.sh

只是为 Aaditya 的答案添加了一些解释,以解释其工作原理。我无法重播,因为我没有足够的声望。

基本上有两个重要步骤要遵循

导出NVM_DIR 位置。如果该文件夹不存在,则需要先创建该文件夹。

export NVM_DIR="$HOME/.nvm"

其次,您需要获取 nvm 的脚本。通常是这样

. "/usr/local/opt/nvm/nvm.sh"

如果第二步中的路径确实有效,可能是因为您的设备中的路径不同。找到它的路径的一种简单方法是使用命令

brew --prefix nvm

输出将是 nvm.sh 文件所在的 nvm 安装目录的路径。在 $() 中设置命令将创建一个子 shell 来获取该路径。我们可以使用它来获取 nvm.sh 脚本的任何位置,如下所示:

. $(brew --prefix nvm)/nvm.sh

使用该命令可替代 .bash_profile.

中的 . "/usr/local/opt/nvm/nvm.sh"