我正在尝试按照这些说明安装NVM

我在终端输入了这个命令:

$ curl https://raw.github.com/creationix/nvm/master/install.sh | sh

运行install后,重启终端并尝试使用以下命令安装Node.js:

$ nvm install 0.8

但我得到的回答是:

-bash: nvm: command not found

我不知道我哪里做错了。

额外的信息,

我一直在其他帖子和论坛中寻找解决方案。我找到了另一个解决办法

$ git clone git://github.com/creationix/nvm.git ~/.nvm

但是每次我尝试的时候,这个就会超时。任何帮助都将不胜感激。谢谢。


当前回答

随着时间的推移,nvm(来自homebrew)改变了安装后的说明。

我在新计算机上找不到nvm_find_nvmrc,直到我替换

export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"  # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"  # This loads nvm bash_completion

with

[ -s "/opt/homebrew/opt/nvm/nvm.sh" ] && \. "/opt/homebrew/opt/nvm/nvm.sh"  # This loads nvm
[ -s "/opt/homebrew/opt/nvm/etc/bash_completion.d/nvm" ] && \. "/opt/homebrew/opt/nvm/etc/bash_completion.d/nvm"  # This loads nvm bash_completion

正确地找到了安装位置。

其他回答

我在MacBook Pro上安装nvm时也遇到过类似的问题。

我最初使用brew安装了nvm:

brew install nvm

但是当我运行命令时:

nvm --version

我得到了错误:

ZSH nvm: command not found .输出说明

以下是我的解决方法:

使用brew安装nvm还不足以让它工作。你还需要做以下事情;

Confirm that the source ~/.zshrc, ~/.bash_profile, ~/.profile, or ~/.bashrc file exists: zsh: ~/.zshrc bash: ~/.bashrc ksh: ~/.profile Else create it using: touch ~/.zshrc touch ~/.bashrc touch ~/.profile Next, run either of the commands below: Note: You can check the referenced link below to get the updated commands. curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash OR wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash Note: Running either of the above commands downloads a script and runs it. The script clones the nvm repository to ~/.nvm, and attempts to add the source lines from the snippet below to the correct profile file (~/.bash_profile, ~/.zshrc, ~/.profile, or ~/.bashrc) export NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ] && printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm")" [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm.

您可以检查下面引用的链接以获得更新后的脚本。

参考:安装和更新NVM

在Windows 8.1 x64中,我也遇到了同样的情况,并收到了以下消息。

NVM install 8.3.0 bash: NVM: command not found Windows . sh

所以,遵循或验证以下步骤-

首先从github.com安装coreybutler/nvm-windows。目前可用的最新版本为1.1.5 vvm -setup.zip,后续将安装程序vvm -setup.exe解压并安装到如下位置:

NVM_HOME    : C:\Users\Administrator\nvm
NVM_SYMLINK : C:\Program Files\nodejs

与此同时,安装程序将管理环境变量的路径如上所述。

现在以管理员身份运行Git Bash,然后。

$ nvm install 8.3.0 all

Downloading node.js version 8.3.0 (64-bit)...
Complete
Creating C:\Users\Administrator\nvm\temp

Downloading npm version 5.3.0... Complete
Installing npm v5.3.0...

Installation complete. If you want to use this version, type

nvm use 8.3.0

$ nvm use 8.3.0
Now using node v8.3.0 (64-bit)

在这里运行你的命令,不使用$前缀,它只是显示在这里,以确定它是一个命令行,现在我们将验证NVM版本。

$ nvm --version
Running version 1.1.5.

Usage:
-----------------------

如果你使用NVM安装node有问题,你可以在这里看到可用的nodejs版本列表https://nodejs.org/download/release/,并根据你的需求版本等于或高于v6.3.0直接选择正确的安装程序。

对于Mac OS:

打开终端 用下面的命令检查你是否有.profile文件:

如果你没有这个文件,就创建一个:

联系~ / . profile

将此命令添加到.profile文件中:

源代码~ sh - nvm - nvm。

按Shift + Esc键,输入wq,按enter键

nvm install脚本默认将初始化代码添加到$HOME/。配置文件,它只由登录shell加载(在桌面环境中,您可能永远不会看到登录shell)。

登录shell中的nvm命令不会传播到子shell(如登录后的控制台窗口和IDE终端)。这个片段在你的$HOME/。Bashrc只会加载NVM,如果它是一个交互式shell并且还没有被加载

# if nvm dir is not set and the standard nvm directory exists
if [ -z "$NVM_DIR" -a -d "$HOME/.nvm" ] ; then
# set nvm dir
  export NVM_DIR="$HOME/.nvm"
fi

# if nvm dir is set and this shell is interactive
if [ -d "$NVM_DIR" -a -n "$PS1" ] ; then
  # if nvm command is not defined
  if ! type -t nvm >/dev/null ; then
    # set it
    source "$NVM_DIR/nvm.sh"
  fi
fi

把这个放在$HOME/。Bashrc文件将修复交互式bash shell中缺少NVM的问题,即使是从gui,即使NVM安装在非标准位置。

迅速的回答

计算如下:

你的终端使用的是哪个shell,输入:echo $0来查找(正常工作) shell在启动时加载哪个启动文件(不是登录shell启动文件,正常的shell启动文件,有区别!) 将source ~/.nvm/nvm.sh添加到该文件(假设该文件存在于该位置,它是默认安装位置) 启动一个新的终端会话 利润?

例子

如您所见,它显示的是zsh而不是bash。

为了解决这个问题,我需要添加源~/.nvm/nvm.sh到~/. nvm.sh。当启动一个新终端时,我的Deepin终端zsh读取~/。ZSHRC而不是bashs ~/.bashrc。

为什么会发生这种情况

这是因为在安装NVM时,它将代码添加到~/。bashrc,因为我的终端Deepin终端使用zsh而不是bash,它永远不会读取~/。bashrc,因此永远不会加载NVM。

换句话说:这是nvm故障。

关于zsh的更多信息可以在这里的一个答案中阅读。

zsh用户的快速回答

curl raw.github.com/creationix/nvm/master/install.sh | zsh