Install Node.js on macOS
On macOS, Homebrew is the path of least resistance.
Option A: Homebrew (recommended)
- Check whether you have Homebrew. Open Terminal and run the command below. If you see a version number, it's installed:
bash
brew -vIf not, install Homebrew first:
bash
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"- Then install Node.js:
bash
brew update
brew install node- Check the install:
bash
node -v
npm -vIf you see version numbers, you're done.
Option B: the official PKG installer (more visual)
- Go to the Node.js website: https://nodejs.org/
- Download the
LTS.pkg - Double-click to install
- Open Terminal and check:
bash
node -v
npm -vIf you see version numbers, you're done.
Troubleshooting
1) Permission errors on npm global installs
Don't force it with sudo npm -g. The cleaner fix is Homebrew's Node, or managing Node versions with nvm.
If you do hit permission errors, reinstall Node with the Homebrew method above first.
2) npm installs are slow (optional)
If npm downloads crawl on your network, you can switch to a mirror registry (and switch back any time):
bash
npm config set registry https://registry.npmmirror.comCheck that it took effect:
bash
npm config get registry