[英]“nvm” command not recognized in new command line windows/tabs despite presence of “NVM_DIR” variable in both ~/.bashrc and ~/.bash_profile
My colleague recently installed Node Version Manager on his Macbook using Homebrew, and ran the two commands suggested at the end of the install script:我的同事最近使用 Homebrew 在他的 Macbook 上安装了 Node Version Manager,并运行了安装脚本末尾建议的两个命令:
export NVM_DIR=~/.nvm
source $(brew --prefix nvm)/nvm.sh
Everything works fine in the terminal window in which the install took place, but if he opens up a new terminal window or even a new tab, he has to install NVM all over again.在进行安装的终端窗口中一切正常,但是如果他打开一个新的终端窗口甚至一个新选项卡,他必须重新安装 NVM。
My level of command-line experience is relatively low (I don't know what I don't know), so I'm not sure where to start diagnosing the problem.我的命令行经验水平相对较低(我不知道我不知道什么),所以我不确定从哪里开始诊断问题。 Suggestions are welcome.欢迎提出建议。
The instructions from brew
after installing nvm
are:安装nvm
后brew
的说明是:
Add the following to $HOME/.bashrc, $HOME/.zshrc, or your shell's equivalent configuration file:
source $(brew --prefix nvm)/nvm.sh
On OS X with default settings, you actually want $HOME/.profile
(or ~/.profile
).在具有默认设置的 OS X 上,您实际上需要$HOME/.profile
(或~/.profile
)。 Just add the line above to the end of that file.只需将上面的行添加到该文件的末尾。
Running that line once will set up nvm
in that shell session.运行该行一次将在该 shell 会话中设置nvm
。 But if you add it to your .profile
file, it will be run at the beginning of every shell session.但是如果您将它添加到您的.profile
文件中,它将在每个 shell 会话开始时运行。
.bash_profile
如果您不想编辑.bash_profile
You could also export the nvm()
function to your current shell enviroment :您还可以将nvm()
函数导出到当前的 shell 环境:
source $(brew --prefix nvm)/nvm.sh
to check that is working:检查是否正常工作:
nvm -v
.bash_profile
如果你想编辑.bash_profile
sudo vim ~/.bash_profile
Type i
to insert, and add:输入i
插入,并添加:
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh"
Press wq!
按wq!
to save and exit and finally restart the terminal application.保存并退出,最后重新启动终端应用程序。
Never Give Up!永不放弃! ✌️ ✌️
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.