How to Install npm on Mac: A Complete Setup Guide
Whether you're jumping into your first JavaScript project or setting up a new development machine, getting npm (Node Package Manager) running on your Mac is one of the first things you'll tackle. The process is straightforward — but there are a few paths to get there, and the right one depends on how you work.
What npm Actually Is (and Why It Comes With Node)
npm is the default package manager for Node.js. It lets you install, manage, and share JavaScript packages and dependencies. The important thing to understand upfront: npm doesn't install on its own. It ships bundled with Node.js, so installing Node is what puts npm on your system.
When you install Node.js, npm comes along automatically. You don't download them separately.
The Three Main Ways to Install npm on Mac
1. The Official Node.js Installer (Simplest Path)
The most beginner-friendly approach is downloading the installer directly from nodejs.org.
- Visit the site and download the macOS installer (.pkg file)
- Run the installer and follow the prompts
- Open Terminal and verify the installation:
node -v npm -v Both commands should return version numbers. If they do, you're set.
This method works well for users who want a quick, no-frills setup and aren't managing multiple projects with conflicting Node versions.
2. Homebrew (Popular Among Developers)
Homebrew is a widely used package manager for macOS. If you're already using it — or plan to — installing Node through Homebrew is clean and easy to maintain.
First, install Homebrew if you haven't already. Paste this into Terminal:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" Then install Node (which includes npm):
brew install node Verify with:
node -v npm -v Homebrew makes updating Node straightforward later with brew upgrade node. The trade-off: it installs a single version system-wide, which can create friction if different projects need different Node versions.
3. nvm — Node Version Manager (Most Flexible) ⚙️
nvm is a tool that lets you install and switch between multiple versions of Node.js on the same machine. This matters more than it might seem: many real-world projects pin to a specific Node version, and running the wrong one can break builds.
Install nvm via Terminal:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash After installation, restart Terminal or source your shell config file (.zshrc or .bash_profile depending on your setup). Then install a Node version:
nvm install --lts This installs the latest LTS (Long-Term Support) release, which is the stable, widely-supported version recommended for most use cases.
Check that everything's working:
node -v npm -v With nvm, you can install multiple Node versions and switch between them using nvm use <version>. That flexibility is why many developers default to this approach.
Comparing the Three Methods
| Method | Best For | Version Control | Complexity |
|---|---|---|---|
| Official Installer | Beginners, one-time setup | Single version | Low |
| Homebrew | Mac power users already using brew | Single version | Low–Medium |
| nvm | Active developers, multiple projects | Multiple versions | Medium |
Common Issues After Installation
npm not recognized after install? This usually means your shell's PATH wasn't updated. Restarting Terminal often fixes it. If not, check that your .zshrc or .bash_profile includes the path to Node.
Permission errors when running npm? Avoid using sudo with npm commands — it's a sign something's misconfigured. With nvm, this problem typically doesn't occur because Node installs into your home directory, not a system-level location.
Which Node version should you install? The LTS version is the safe default for most developers. The Current version includes newer features but may have less ecosystem support. If a project's documentation specifies a version, use that.
Keeping npm Updated 🔄
Once npm is installed, you can update it independently of Node:
npm install -g npm@latest It's worth doing periodically, as npm releases often include security patches and performance improvements.
What Shapes the Right Setup for You
The installation method that makes the most sense varies significantly based on a few factors:
- How many projects you're working on — a single personal project has different demands than a professional environment with multiple codebases
- Your existing toolchain — if Homebrew is already part of your workflow, adding Node through it keeps things consistent
- Your comfort with Terminal — the official installer requires the least command-line familiarity; nvm requires the most
- macOS version — Apple Silicon Macs (M1/M2/M3) and Intel Macs both support all three methods, but some older tutorials reference workarounds that may or may not apply to your chip
- Team or project requirements — if you're joining an existing team, they may already have a preferred setup or a
.nvmrcfile that specifies a Node version
Understanding what npm is and how it gets onto your Mac is the easy part. The decision that has more long-term consequence is which installation method fits your actual workflow — and that depends on where you're starting from and where your projects are headed. 🖥️