转载自:https://blog.csdn.net/q375537943/article/details/131958222
=========
一、查看当前node.js版本
node -v
二、卸载当前node.js
# 这里是卸载npm的
sudo npm uninstall npm -g
# 这里是用来删除node创建的各种文件夹
sudo rm -rf /usr/local/lib/node
sudo rm -rf /usr/local/lib/node_modules
sudo rm -rf /var/db/receipts/org.nodejs.*
sudo rm -rf /usr/local/include/node /Users/$USER/.npm*
# 删除node命令
sudo rm /usr/local/bin/node
# 删除node的所有man手册
sudo rm /usr/local/share/man/man1/node.1
sudo rm /usr/local/share/man/man1/npm-*
sudo rm /usr/local/share/man/man1/npm.1
sudo rm /usr/local/share/man/man1/npx.1
sudo rm /usr/local/share/man/man5/npm*
sudo rm /usr/local/share/man/man5/package.json.5
sudo rm /usr/local/share/man/man7/npm*
三、安装指定版本的node.js
3.1 安装
安装14版本的node.js
brew install node@14
安装16版本的node.js
brew install node@16
3.2 配置环境变量
在终端中,执行
echo 'export PATH="/opt/homebrew/opt/node@14/bin:$PATH"' >> ~/.zshrc
使环境变量生效
source ~/.zshrc
查看node安装成功
node -v