1.命令安装
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.6/install.sh | bash
安装完成后会显示
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
2.配置bash_profiile(我安装后没有配置,nvm命令就有了)
将上面的复制到bash_profile中
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
3.先打开终端查看版本 nvm --version
MacBook-Pro ~ % nvm --version
0.33.6
4.报错
每次打开终端后莫名显示错误
complete:13: command not found: compdef
解决方法一:
注释bash_profile中的最后一行(https://stackoverflow.com/questions/66338988/complete13-command-not-found-compdef)
解决方法二:
方法一对我的问题没起作用,注释nvm中bash_completion文件的代码
I commented out the last line (complete -o default -F __nvm nvm) from /usr/share/nvm/bash_completion and I no long get the error. I assume this breaks auto completion but I never really used it anyway.
找到代码处,用#注释掉