1 在终端依次输入以下命令
sudo npm uninstall npm -g
sudo rm -rf /usr/local/lib/node /usr/local/lib/node_modules /var/db/receipts/org.nodejs.*
sudo rm -rf /usr/local/include/node /Users/$USER/.npm
sudo rm /usr/local/bin/node
sudo rm /usr/local/share/man/man1/node.1
sudo rm /usr/local/lib/dtrace/node.d
sudo rm -rf /usr/local/lib/node /usr/local/lib/node_modules /var/db/receipts/org.nodejs.*
sudo rm -rf ~/.node-gyp
sudo rm -rf ~/.npm
sudo rm -rf /opt/local/lib/node_modules
sudo rm -rf /usr/local/opt/node*
sudo rm -rf /usr/local/Cellar/node*
2 验证是否成功
node -v
-bash: node: command not found
npm -v
-bash: npm: command not found
3 node 安装地址(可忽略,不用下载)
http://nodejs.cn/download/
4 查找node可用版本
brew search node
5 安装需要的版本
brew install node@12
6 链接版本
brew link node@12
7 添加环境变量
echo 'export PATH="/usr/local/opt/node@12/bin:$PATH"' >> ~/.bash_profile
export LDFLAGS="-L/usr/local/opt/node@12/lib"
export CPPFLAGS="-I/usr/local/opt/node@12/include"
8 重新打开终端,查看版本
node -v
v12.16.1
注:
我的项目用nodev13太高,nodev10又太低,根据实际情况;
参考:
https://www.jianshu.com/p/6dcfc0d3ea40
https://zhuanlan.zhihu.com/p/108858395?from_voters_page=true
https://www.cnblogs.com/ZhaoWeiNotes/p/11605745.html
网友评论