安装homebrew
/bin/zsh -c "$(curl -fsSL https://gitee.com/cunkai/HomebrewCN/raw/master/Homebrew.sh)"
使用brew安装nvm
brew install nvm
如果出现报错:error: could not lock config file .git/config: Permission denied
sudo chown -R $(whoami) /usr/local
出现:chown: /usr/local: Operation not permitted 成功
再重新执行,如果安装成功,则显示类似如下信息
Bash completion has been installed to:
/usr/local/etc/bash_completion.d
==> Summary
🍺 /usr/local/Cellar/nvm/0.39.0: 7 files, 181.3KB
配置环境变量
open ~/.bash_profile
在bash_profile文件中添加
export NVM_DIR="$HOME/.nvm"
[ -s "/usr/local/opt/nvm/nvm.sh" ] && . "/usr/local/opt/nvm/nvm.sh" # This loads nvm
[ -s "/usr/local/opt/nvm/etc/bash_completion.d/nvm" ] && . "/usr/local/opt/nvm/etc/bash_completion.d/nvm" # This loads nvm bash_completion
source ~/.bash_profile
验证nvm是否安装成功
nvm —version
安装指定版本的node
nvm install 6.17.1
? 安装最新稳定版 node
nvm install stable
列出远程服务器上所有的可用的node版本
nvm ls-remote
在不同版本切换
切换到最新版
nvm use node
使用指定的版本
nvm use 6.17.1
列出已安装的node
nvm ls
|