安装nvm
bash
brew install nvm
安装成功后会出现这样一段话:
bash
Add the following to your shell profile e.g. ~/.profile or ~/.zshrc:
export NVM_DIR="$HOME/.nvm"
[ -s "/opt/homebrew/opt/nvm/nvm.sh" ] && \. "/opt/homebrew/opt/nvm/nvm.sh" # This loads nvm
[ -s "/opt/homebrew/opt/nvm/etc/bash_completion.d/nvm" ] && \. "/opt/homebrew/opt/nvm/etc/bash_completion.d/nvm" # This loads nvm bash_completion
把这段话拷贝到 ~/.bash_profile中
bash
vim ~/.bash_profile
即拷贝下面这段话
bash
export NVM_DIR="$HOME/.nvm"
[ -s "/opt/homebrew/opt/nvm/nvm.sh" ] && \. "/opt/homebrew/opt/nvm/nvm.sh"
然后让配置生效
bash
source ~/.bash_profile
输入nvm -v就能看到安装版本了。
记得装个镜像,但mac homebrew安装我暂时找不到nvm安装目录(TODO)
npm的镜像设置可参考 pip镜像管理和npm镜像管理
常用命令
bash
nvm install x.x.x
例如安装20.2.5版本的node
bash
nvm install 20.2.5