node -v
# 这里是卸载npm的sudo npm uninstall npm -g# 这里是用来删除node创建的各种文件夹sudo rm -rf /usr/local/lib/nodesudo rm -rf /usr/local/lib/node_modulessudo 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.1sudo rm /usr/local/share/man/man1/npm-*sudo rm /usr/local/share/man/man1/npm.1sudo rm /usr/local/share/man/man1/npx.1sudo rm /usr/local/share/man/man5/npm*sudo rm /usr/local/share/man/man5/package.json.5sudo rm /usr/local/share/man/man7/npm*
3.1 安装
安装14版本的node.js
brew install node@14
安装18版本的node.js
brew install node@18
3.2 配置环境变量
在终端中,执行
echo 'export PATH="/opt/homebrew/opt/node@14/bin:$PATH"' >> ~/.zshrc
使环境变量生效
source ~/.zshrc
查看node安装成功
node -v
来源地址:https://blog.csdn.net/qq_39208536/article/details/130965206