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

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


当前回答

在花了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

其他回答

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

迅速的回答

计算如下:

你的终端使用的是哪个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

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

与问题没有直接联系,但可能会发生类似的问题,看看这个问题:无法从new bash执行nvm


以下是我对那篇文章的回答,仅供参考:

如果您正在从一个新的bash实例运行,并且您的~/。bashrc,(~ /。Bash_profile等,然后需要检查这个初始化文件中的条件。

在Ubuntu 14上,有一个:

case $- in
    *i*) ;;
      *) return;;
esac

在第6行,如果bash没有使用“-i”(交互式)标志运行,将暂停它的执行。所以你需要运行:

bash -i

此外,在文件的末尾,有一个

[ -z "$PS1" ] && return

如果没有使用$PS1设置运行(就像在远程ssh会话上),这将停止它的执行。

如果您不希望添加任何env变量或标志,则需要从初始化文件中删除这些条件。

希望这对大家有帮助。

在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更可取。在这里看到的。