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

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


当前回答

假设你已经使用brew安装了nvm(我在mac上),我的意思是像brew安装nvm这样的东西,你所需要做的就是:

 1. You should create NVM's working directory if it doesn't exist:

  mkdir ~/.nvm

 2. Add the following to ~/.zshrc or your desired shell configuration
    file:

      export NVM_DIR="$HOME/.nvm"
      [ -s "/usr/local/opt/nvm/nvm.sh" ] && . "/usr/local/opt/nvm/nvm.sh"  # This loads nvm
      [ -s "/usr/local/opt/nvm/etc/bash_completion.d/nvm" ] && . "/usr/local/opt/nvm/etc/bash_completion.d/nvm"  # This loads nvm bash_completion

其他回答

对于Mac OS:

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

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

创建概要文件

touch ~/.bash_profile

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

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

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

.  ~/.bash_profile

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

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

打开终端 用下面的命令检查你是否有.profile文件:

如果你没有这个文件,就创建一个:

联系~ / . profile

将此命令添加到.profile文件中:

源代码~ sh - nvm - nvm。

按Shift + Esc键,输入wq,按enter键