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

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


当前回答

如果您使用的是OS X,那么在运行安装命令之前可能必须创建.bash_profile文件。这对我很有帮助。

创建概要文件

touch ~/.bash_profile

重新运行安装,这次您将在输出中看到相关行。

=>向/Users/{username}/.bash_profile添加源字符串

重新加载您的配置文件(或关闭/重新打开终端窗口)。

.  ~/.bash_profile

其他回答

在花了3个多小时测试上面的一些解决方案后,我找到了一个对我有用的答案。 我在Ubuntu 20.04.3 LTS下,并在新的安装中添加了官方命令:

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/install.sh | 
bash

问题是我的curl版本是通过snap获得的。删除它并重新安装它,根据这个答案修复了这个问题:

sudo snap remove curl
sudo apt install curl
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/install.sh 
| bash
nvm install node

对于Mac OS:

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

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

打开终端 如果你有ZSH终端,那么输入命令'open ~/.zshrc' 添加文件结尾,保存如下: ~ / .nvm / nvm.sh来源

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