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

其他回答

对于Mac OS:

打开终端 运行touch ~/.bash_profile 执行vi ~/.bash_profile命令 输入source ~/.nvm/nvm.sh 按Shift + Esc键,输入wq,按enter键 完成了。

检查您的.bash_profile、.zshrc或.profile文件。您很可能在安装过程中遇到了问题。

您应该在其中一个文件的末尾看到以下内容。

[[ -s $HOME/.nvm/nvm.sh ]] && . $HOME/.nvm/nvm.sh  # This loads NVM

的。$HOME/.nvm/nvm.sh与源文件$HOME/.nvm/nvm.sh相同

参见:源文件

您还可以检查是否有.nvm文件夹。

ls -a | grep .nvm

如果您缺少该文件夹,则安装运行git命令失败。这可能是由于背后的代理。试着运行下面的程序。

git clone http://github.com/creationix/nvm.git .nvm

OSX 10.15.0 Catalina(2019年11月发布)将默认shell更改为zsh。

默认shell以前是bash。

nvm GitHub页面上给出的安装命令需要调整,以在末尾包含“zsh”。

curl https://raw.githubusercontent.com/creationix/nvm/master/install.sh | zsh

注意:你可能需要确保zsh的.rc文件预先存在:

touch ~/.zsrhrc

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安装在非标准位置。

所有这些问题的答案都是有用的。尤其是特拉维斯给出的答案帮助了我。对于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.