C.W.K.
Stream
Lesson 02 of 05 · published

Install + Upgrade npm

~8 min · npm, installation, node

Level 0Newbie
0 XP0/55 lessons0/16 achievements
0/80 XP to next level80 XP to go0% complete

npm comes bundled with Node.js. The cleanest install path is to install Node via Homebrew, which gets you npm automatically. There are alternatives — nvm and fnm let you run multiple Node versions side-by-side, mise/asdf are polyglot version managers — but for a beginner, brew install node is the right first step.

Once Node is installed, npm is on your PATH. You can upgrade npm independently of Node (the bundled npm is often a few minor versions behind the latest npm). npm install -g npm@latest upgrades npm itself.

One upgrade gotcha: npm install -g npm@latest can sometimes fail with permission errors on macOS if npm's global prefix is in a system path. The cleanest fix is to set npm's global prefix to a user-owned directory like ~/.npm-global, then add ~/.npm-global/bin to your PATH. Or skip the global install entirely and let Homebrew's Node bundle handle the npm version.

Code

Install Node + npm via Homebrew·bash
# Install Node (npm bundled)
brew install node

# Verify
node --version
npm --version

# Optional — upgrade npm to latest
npm install -g npm@latest
Avoid global-permission pain·bash
# Set npm's global prefix to a user-owned dir
mkdir -p ~/.npm-global
npm config set prefix '~/.npm-global'

# Add it to your PATH
echo 'export PATH="$HOME/.npm-global/bin:$PATH"' >> ~/.zprofile
source ~/.zprofile

# Now 'npm install -g <pkg>' installs to ~/.npm-global/ — no sudo needed.

External links

Exercise

Run 'npm config get prefix' and check where global packages would land. If it's a system path, run the snippet above to relocate to ~/.npm-global. This is a 5-minute change that prevents an evening of permission debugging later.

Progress

Progress is local-only — sign in to sync across devices.
Spotted a bug or have feedback on this page?Report an Issue

Comments 0

🔔 Reply notifications (sign in)
Sign inPlease sign in to comment.

No comments yet — be the first.