node.js 节点版本管理器安装 - 未找到 nvm 命令
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16904658/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Node Version Manager install - nvm command not found
提问by jordan
I am trying to install NVM as per these instructions
我正在尝试按照这些说明安装 NVM
I typed in this command in terminal:
我在终端中输入了这个命令:
$ curl https://raw.github.com/creationix/nvm/master/install.sh | sh
After running the install, I restart the terminal and attempt to install Node.js with this command:
运行安装后,我重新启动终端并尝试使用以下命令安装 Node.js:
$ nvm install 0.8
but I get the response:
但我得到了回应:
-bash: nvm: command not found
I'm not sure what I am doing wrong here.
我不确定我在这里做错了什么。
Additional Info--
附加信息 -
I've been looking around for solutions from other posts and forums. I found another solution using
我一直在寻找其他帖子和论坛的解决方案。我找到了另一个解决方案
$ git clone git://github.com/creationix/nvm.git ~/.nvm
but this times out every time I attempt that. Any help would be appreciated. Thanks.
但是每次我尝试这样做时都会超时。任何帮助,将不胜感激。谢谢。
回答by Deepak Lamichhane
I think you missed this step:
我想你错过了这一步:
source ~/.nvm/nvm.sh
You can run this command on the bash OR you can put it in the file /.bashrc or ~/.profile or ~/.zshrc to automatically load it
您可以在 bash 上运行此命令,也可以将其放在文件 /.bashrc 或 ~/.profile 或 ~/.zshrc 中以自动加载它
回答by travis
Check your .bash_profile, .zshrc, or .profilefile. You most likely had a problem during the installation.
检查你的.bash_profile, .zshrc或.profile文件。您很可能在安装过程中遇到了问题。
You should have the following at the end of one of those files.
您应该在这些文件之一的末尾有以下内容。
[[ -s $HOME/.nvm/nvm.sh ]] && . $HOME/.nvm/nvm.sh # This loads NVM
The . $HOME/.nvm/nvm.shis the same as source $HOME/.nvm/nvm.sh
该. $HOME/.nvm/nvm.sh是一样的source $HOME/.nvm/nvm.sh
See: Sourcing a File
请参阅:获取文件
You can also check to see if you have a .nvmfolder.
您还可以检查是否有.nvm文件夹。
ls -a | grep .nvm
If you're missing that folder then the installation failed to run the git command. This could be due to being behind a proxy. Try running the following instead.
如果您缺少该文件夹,则安装无法运行 git 命令。这可能是由于在代理后面。尝试运行以下命令。
git clone http://github.com/creationix/nvm.git .nvm
回答by Alireza
This works for me:
这对我有用:
Before installing
nvm, run this in terminal:touch ~/.bash_profileAfter, run this in terminal:
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.1/install.sh | bashImportant...- DO NOT forget to Restartyour terminal ORuse command
source ~/.nvm/nvm.sh(this will refresh the available commands in your system path).In the terminal, use command
nvm --versionand you should see the version
在安装之前
nvm,在终端中运行它:touch ~/.bash_profile之后,在终端中运行:
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.1/install.sh | bash重要...- 不要忘记重新启动终端或使用命令
source ~/.nvm/nvm.sh(这将刷新系统路径中的可用命令)。在终端中,使用命令
nvm --version,您应该会看到版本
回答by user2015258
source ~/.nvm/nvm.shAdd this line to ~/.bashrc, ~/.profile, or ~/.zshrc
source ~/.nvm/nvm.sh将此行添加到 ~/.bashrc、~/.profile 或 ~/.zshrc
回答by Karl Morrison
Quick answer
快速回答
Figure out the following:
弄清楚以下几点:
- Which shell is your terminal using, type in:
echo $0to find out (normally works) - Which start-up file does that shell load when starting up (NOT login shell starting file, the normal shell starting file, there is a difference!)
- Add
source ~/.nvm/nvm.shto that file (assuming that file exists at that location, it is the default install location) - Start a new terminal session
- Profit?
- 您的终端使用哪个 shell,输入:
echo $0以找出(通常有效) - 启动时该shell加载哪个启动文件(不是登录shell启动文件,正常的shell启动文件,有区别!)
- 添加
source ~/.nvm/nvm.sh到该文件(假设该文件存在于该位置,则它是默认安装位置) - 开始一个新的终端会话
- 利润?
Example
例子
As you can see it states zshand not bash.

正如你所看到的,它声明zsh而不是bash。

To fix this I needed to add source ~/.nvm/nvm.shto the ~/.zshrcfile as when starting a new terminal my Deepin Terminal zsh reads ~/.zshrcand not bashs ~/.bashrc.
为了解决这个问题,我需要在启动新终端时添加source ~/.nvm/nvm.sh到~/.zshrc文件中,我的深度终端 zsh 读取~/.zshrc而不是 bashs ~/.bashrc。
Why does this happen
为什么会发生这种情况
This happens because when installing NVM it adds code to ~/.bashrc, as my terminal Deepin Terminal uses zshand not bashit never reads ~/.bashrcand therefor never loads NVM.
这是因为安装NVM时,增加了代码~/.bashrc,作为我的终端Deepin终端使用zsh,而不是bash它从不读取~/.bashrc并为此从未负荷NVM。
In other words: this is NVMs fault.
换句话说:这是 NVM 的错误。
More on zshcan be read on one of the answers here.
有关更多信息,请zsh阅读此处的答案之一。
回答by hd84335
In macOS, i had to source it using source ~/.nvm/nvm.shcommand to fix this problem.
在 macOS 中,我不得不使用source ~/.nvm/nvm.sh命令来解决这个问题。
After that, add these lines
之后,添加这些行
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" # This loads nvm
onto ~/.bash_profileso that nvm will be sourced automatically upon login.
在~/.bash_profile使NVM将在登录后自动加载。
回答by S.Mishra
All answers to this questions are useful. Especially the answer given by Travis helped me. For Mac OS X users I would like to provide some steps which will help them to work with the fresh installation of Node Version Manager a.k.a. nvm.
这个问题的所有答案都是有用的。特别是特拉维斯给出的答案对我有帮助。对于 Mac OS X 用户,我想提供一些步骤来帮助他们使用 Node Version Manager aka nvm 的全新安装。
Installing & using nvm on Mac OS X
在 Mac OS X 上安装和使用 nvm
Here are the steps for fresh installation of nvm and using it without any issue:
以下是全新安装 nvm 并在没有任何问题的情况下使用它的步骤:
- Install homebrew from here.
Using homebrew install nvm
brew update brew install nvmCreate
.nvmdirectory at~/.nvmlocation.mkdir ~/.nvmNow if you don't have
.bash_profilefile setup for OS X terminal then please create a.bash_profileat the root level:nano ~/.bash_profilePaste below code in the
.bash_profileand pressCTRL + Oand press enter to save.bash_profilefile. PressCTRL + Xto exit from editor:export NVM_DIR=~/.nvm source $(brew --prefix nvm)/nvm.shNow either quite (
CMD + Q) the terminal or run below command to load.bash_profilesettings:source ~/.bash_profileNow run
nvm lscommand to get the list of all installed nodejs versions.
- 从这里安装自制软件。
使用自制软件安装 nvm
brew update brew install nvm.nvm在~/.nvm位置创建目录。mkdir ~/.nvm现在,如果您没有
.bash_profile为 OS X 终端设置文件,请.bash_profile在根级别创建一个:nano ~/.bash_profile将下面的代码粘贴到 中
.bash_profile,然后CTRL + O按回车键保存.bash_profile文件。按CTRL + X退出编辑器:export NVM_DIR=~/.nvm source $(brew --prefix nvm)/nvm.sh现在要么完全 (
CMD + Q) 终端或运行下面的命令来加载.bash_profile设置:source ~/.bash_profile现在运行
nvm ls命令以获取所有已安装 nodejs 版本的列表。
回答by KARTHIKEYAN.A
First add following lines in ~/.bashrc file
首先在 ~/.bashrc 文件中添加以下几行
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
then open terminal and source the nvm.sh script
然后打开终端并获取 nvm.sh 脚本
source ~/.nvm/nvm.sh
回答by Ben Aston
OSX 10.15.0 Catalina(released November 2019) changed the default shell to zsh.
OSX 10.15.0 Catalina(2019 年 11 月发布)将默认 shell 更改为 zsh。
The default shell was previously bash.
默认的 shell 以前是 bash。
The installation command given on the nvm GitHub pageneeds to be tweaked to include "zsh" at the end.
需要调整nvm GitHub 页面上给出的安装命令以在末尾包含“zsh”。
curl https://raw.githubusercontent.com/creationix/nvm/master/install.sh | zsh
Note: you might need to ensure the .rcfile for zsh is present beforehand:
注意:您可能需要.rc事先确保zsh的文件存在:
touch ~/.zsrhrc
回答by Arjun Kesava
For Mac OS:
对于 Mac 操作系统:
- Open Terminal
- Run
touch ~/.bash_profile - Run
vi ~/.bash_profile - Type
source ~/.nvm/nvm.sh - Press
Shift + Escand typewqand pressenter - Done.
- 打开终端
- 跑
touch ~/.bash_profile - 跑
vi ~/.bash_profile - 类型
source ~/.nvm/nvm.sh - 按下
Shift + Esc并输入wq并按下enter - 完毕。

