我正在尝试按照这些说明安装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

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


当前回答

所有这些问题的答案都是有用的。尤其是特拉维斯给出的答案帮助了我。对于Mac OS X用户,我想提供一些步骤,这将帮助他们与节点版本管理器(又名nvm)的新安装。

在Mac OS X上安装和使用nvm

以下是重新安装nvm并毫无问题地使用它的步骤:

Install homebrew from here. Using homebrew install nvm brew update brew install nvm Create .nvm directory at ~/.nvm location. mkdir ~/.nvm Now if you don't have .bash_profile file setup for OS X terminal then please create a .bash_profile at the root level: nano ~/.bash_profile Paste below code in the .bash_profile and press CTRL + O and press enter to save .bash_profile file. Press CTRL + X to exit from editor: export NVM_DIR=~/.nvm source $(brew --prefix nvm)/nvm.sh Now either quite (CMD + Q) the terminal or run below command to load .bash_profile settings: source ~/.bash_profile Now run nvm ls command to get the list of all installed nodejs versions.

其他回答

在Debian上,以及添加以下行到我的.bash_profile正如上面的答案之一所说。我还不得不打开我的终端首选项(编辑->配置文件首选项->命令),并启用“运行命令作为登录shell”,以使其工作。

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

编辑:对于Mac用户,请注意macOS在终端启动时不读取.bashrc,因此使用.bash_profile更可取。在这里看到的。

在文件中添加以下行~/。Bashrc和~/。bash_profile:

# NVM changes
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"

并重新启动终端或做源~/。Bashrc或source ~/.bash_profile。如果你需要nvm的命令补全,也可以添加这行:

[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"

与上面的行一起到~/。Bashrc和~/.bash_profile。

在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直接选择正确的安装程序。

source ~/.nvm/nvm.sh将这一行添加到~/。bashrc,(~ /。或者~/.zshrc

首先在~/中添加以下行。bashrc文件(

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

然后打开terminal并源nvm.sh脚本

source ~/.nvm/nvm.sh