更新:建議使用nvm官方GitHub文檔安裝方式
參考文檔:https://github.com/nvm-sh/nvm/blob/master/README.md#installing-and-updating
安裝brew
終端上運行
$ /usr/bin/ruby -e “$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)”
安裝NVM
$ brew install nvm
安裝完成之后打開shell的配置文件
$ cd ~ $ vim ~/.zshrc # 如果是bash的話執行 $ vim .bash_profile
在文件里添加以下命令
export NVM_DIR=~/.nvm source $(brew --prefix nvm)/nvm.sh
然后重新source
$ source ~/.zshrc # 如果是bash的話執行 $ source .bash_profile
使用nvm安裝node
$ nvm ls-remote 查看 所有的node可用版本 $ nvm install xxx 下載你想要的版本 $ nvm use xxx 使用指定版本的node $ nvm alias default xxx 每次啟動終端都使用該版本的node