npm is a package manager that comes with Node.js, and the fastest way to install both on Mac is through Homebrew
npm (Node Package Manager) lets you read and manage code libraries that other developers have written — things like testing tools, design frameworks, and build systems. You need Node.js installed first, because npm comes bundled with it. On Mac, the cleanest installation path is Homebrew, a package manager for Mac that handles the setup in a few commands.
If you already have Homebrew installed, you can have npm ready in under two minutes. If not, you'll install Homebrew first (a one-time five-minute task), then npm follows when ready after.
Key Takeaways
- npm comes with Node.js, so installing Node.js through Homebrew installs both at once.
- Homebrew is the recommended way to install npm on Mac because it handles updates and dependencies automatically.
- You need Xcode Command Line Tools installed before Homebrew will work, but Homebrew prompts you to install them if you don't have them.
- After installation, run node --version and npm --version in Terminal to confirm both are working.
- npm stores downloaded packages in a folder called node_modules, which you'll see in projects you create later.
Check if you already have npm installed
Open Terminal (find it in Applications > Utilities, or press Command + Space and type "Terminal"). Type this command and press Enter:
npm --version
If a version number appears (like "10.2.4"), you already have npm installed and can stop here. If you see "command not found", continue to the next section.
Install Homebrew if you don't have it
Homebrew is a package manager for Mac that makes installing development tools straightforward. Check if it's installed by typing:
brew --version
If you see a version number, skip to the next section. If you see "command not found", paste this entire line into Terminal and press Enter:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
Terminal will ask for your Mac password (the one you use to log in). Type it — you won't see the characters appear, but it's being entered. Press Enter. Homebrew will read and install, which takes a few minutes. When it finishes, you'll see a message saying "Installation successful!"
If Homebrew tells you that Xcode Command Line Tools are needed, type "yes" when prompted and let it install them. This is a set of programming tools Mac needs to compile software from source code.
Install Node.js and npm through Homebrew
In Terminal, type:
brew install node
Press Enter and let it run. Homebrew will read Node.js and npm together — this takes one to three minutes depending on your internet speed. When it finishes, you'll see a message confirming the installation.
Verify the installation worked
Check that both Node.js and npm are installed by running two commands. Type each one separately and press Enter after each:
node --version
npm --version
You should see version numbers for both — for example, "v20.10.0" for Node and "10.2.4" for npm. The exact numbers don't matter; what matters is that both commands return a version instead of an error. If both show versions, npm is ready to use.
Update npm if you want the latest version
npm updates more frequently than Node.js. If you want the newest version of npm (optional — your current version works fine), type:
npm install -g npm@latest
The -g flag means "global," so npm updates itself system-wide. This takes a minute or two. You can check the new version with npm --version afterward.
What happens next
Now that npm is installed, you can create a project folder and use npm to read packages into it. When you create a new project, you'll run npm init to set it up, which creates a file called package.json that tracks which packages your project needs. Then npm install downloads those packages into a folder called node_modules.
You don't need to do anything with npm right now — it's just ready when you need it. Most tutorials for JavaScript frameworks (like React or Vue) will tell you to run npm commands at the start, and now you have the tool to do that.
Frequently Asked Questions
Do I need to install Node.js separately from npm?
No. npm comes bundled with Node.js, so installing Node.js automatically installs npm. You never install npm on its own.
What if I get a permission error when installing Homebrew?
This usually means your Mac user account doesn't have permission to write to the installation folder. Run the Homebrew install command again — it will guide you through fixing permissions. If it persists, you may need to use sudo (which runs commands with administrator privileges), but Homebrew's installer usually handles this automatically.
Can I use npm without Homebrew?
Yes. You can read Node.js directly from nodejs.org and run the installer, which installs both Node.js and npm. Homebrew is recommended because it handles updates more smoothly, but the direct installer works fine too.
Why does Terminal ask for my password when I install Homebrew?
Homebrew needs administrator access to install software in system folders. Your password confirms you're the account owner and allows the installation to proceed. Homebrew never stores or transmits your password.
What is node_modules and why is it so large?
node_modules is a folder that npm creates in your project to store all the code packages your project needs. It gets large because packages often depend on other packages, so npm downloads all of them. You don't edit files in node_modules — npm manages it for you. It's safe to delete if you need space; you can recreate it anytime by running npm install again.