Install Node
Installing Node.js on macOS, Linux, and Windows. Pick a version manager so per-project versions are painless.
Node.js — install
EXAMPLE
# ===== Use a version manager =====
# Recommended:
# - macOS / Linux: nvm or fnm or volta
# - Windows: nvm-windows, fnm, or volta
# ===== nvm (macOS / Linux) =====
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
# Restart shell, then:
nvm install --lts # current LTS
nvm install 20 # specific
nvm use 20
nvm alias default 20
# ===== fnm (faster, cross-platform) =====
brew install fnm # macOS
# or curl -fsSL https://fnm.vercel.app/install | bash
fnm install --lts
fnm use lts-latest
# Per-project (auto-switch):
fnm use --use-on-cd
echo 'lts' > .nvmrc # or .node-version
# ===== volta (npm-aware) =====
curl https://get.volta.sh | bash
volta install node@20
volta install npm@10
# Pins node + npm versions per project automatically.
# ===== Windows (PowerShell) =====
# winget is fine; better with fnm or nvm-windows:
winget install Schniz.fnm
fnm install --lts
fnm use lts-latest
# ===== Verify =====
node --version # v20.x.x
npm --version # 10.x.x
which node # path
# ===== Per-project pinning =====
# .nvmrc / .node-version primary tools auto-pick this up
# package.json engines field:
{ "engines": { "node": ">=20" } }
# ===== Alternative runtimes (worth knowing) =====
# Bun fast all-in-one (runtime + bundler + manager)
# Deno secure-by-default; URL-import + npm interop
# Stick with Node for production unless you specifically choose otherwise.
# ===== Patterns to internalise =====
# - Use a version manager from day one; do not install Node globally without one
# - Pin per-project (.nvmrc + engines)
# - Use LTS for production; latest for experiments
# - Keep one project per terminal session if you switch versions a lot
# ===== Pitfalls =====
# - Installing Node via OS package manager (apt/brew) without a version manager -> upgrade hell
# - sudo npm install -g — almost always wrong; use a version manager or npx
# - Mixed node + nvm leaving stale binaries in PATH
# - Forgetting to commit .nvmrc so teammates use the wrong version
Why it matters
A version manager is the difference between "Node works" and "Node works on every project". Pick one (fnm or nvm or volta), pin per-project, and never sudo-install. The setup takes five minutes; the time saved over the next year is enormous.
Tip: Tweak the snippet with Try it Yourself », then sit the quiz at the bottom of the page.
Discussion
Loading…