How to install Node.js and npm on a Mac using Homebrew
Step 1. Update Homebrew
Run
brew update
It is recommended that you always update Homebrew before installing new formulae. Homebrew will also try to update automatically every time you install new formulae, but you can disable that by setting HOMEBREW_NO_AUTO_UPDATE=1.
Step 2. Install Node.js
Run
brew install node
npm will be installed together with Node.js.
Step 3. Check your installation
Run
node
This will open the Node.js REPL. Execute a sample script, e.g.
function fib(n) {
if (n < 3) {
return 1
}
return fib(n - 1) + fib(n - 2)
}
fib(18)Recommended for you
Product
Ea.
Hyperbolic Paraboloid Poster, Technical Illustration, Kyrgyz-Labeled
Mandaic Alphabet Chart, 8.3 x 11.7 in (21.0 x 29.7 cm, Desk Chart, Laminated), Chinese (Traditional)-Labeled
2026 Wall Calendar, Marathi-Labeled, Monday-Start Layout, Poster / Wall Print, 23.4 x 33.1 in (59.4 x 84.1 cm)
Normal Distribution Poster, Korean-Labeled
перепись Morphemic Analysis Poster