Mac下安装brew 并使用brew安装Node.js

2,606 阅读1分钟

搜索brew支持的node版本

brew search node

下载安装brew

brew reinstall node@16

根据brew reinstall node@16提示:

If you need to have node@16 first in your PATH, run:

echo 'export PATH="/opt/homebrew/opt/node@16/bin:$PATH"' >> ~/.zshrc

将node加入环境变量方便在命令行使用

echo 'export PATH="/opt/homebrew/opt/node@16/bin:$PATH"' >> ~/.zshrc

 export LDFLAGS="-L/opt/homebrew/opt/node@16/lib"

 export CPPFLAGS="-I/opt/homebrew/opt/node@16/include"

重启终端命令生效

node -v


npm -v

设置npm镜像地址

npm config set registry https://registry.npmmirror.com