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

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


当前回答

我在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

其他回答

我认为你错过了这一步:

source ~/.nvm/nvm.sh

您可以在bash上运行此命令,也可以将其放在文件/中。Bashrc或~/。Profile或~/。ZSHRC自动加载它

https://github.com/creationix/nvm

我已经解决了这个问题。

联系~ / . bash_profile 开放的~ / . bash_profile pasteexport NVM_DIR = " $ HOME / .nvm” [-s "$NVM_DIR/nvm.sh"] && \。"$NVM_DIR/nvm.sh [-s "$NVM_DIR/bash_completion"] && \。"$NVM_DIR/bash_completion" #加载nvm bash_completion

在文件中添加以下行~/。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。

这对我来说很管用:

在安装nvm之前,请在terminal: touch ~/.bash_profile中运行此命令 之后,在终端中运行: Curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.1/install.sh | bash 重要的……-不要忘记重新启动您的终端或使用命令源~/.nvm/nvm.sh(这将刷新系统路径中的可用命令)。 在终端中,使用命令nvm——version,您应该会看到版本

因为这个问题在我搬家时已经解决了

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

到.zshrc的末尾