If you see zsh: command not found: npm, it usually means Node.js isn't installed. npm comes bundled with Node.

Install Node to get npm:

brew install node

Then verify:

npm --version

If Node Is Already Installed

Check if it's a PATH issue:

which node
which npm

If node returns a path but npm doesn't, something went wrong with your Node installation. Reinstall:

brew reinstall node

The Full Installation

Step 1: Install Homebrew (if needed)

/bin/bash -c "\$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

Follow the instructions at the end to add Homebrew to your PATH.

Step 2: Install Node (which includes npm)

brew install node

Step 3: Verify

node --version
npm --version

Both should show version numbers.

PATH Issues

Apple Silicon Macs (M1, M2, M3, M4):

Add Homebrew to your PATH:

echo 'export PATH="/opt/homebrew/bin:\$PATH"' >> ~/.zshrc
source ~/.zshrc

Intel Macs:

echo 'export PATH="/usr/local/bin:\$PATH"' >> ~/.zshrc
source ~/.zshrc

Using nvm

If you use nvm (Node Version Manager), make sure it's loaded in your shell:

Add this to ~/.zshrc:

export NVM_DIR="\$HOME/.nvm"
[ -s "\$NVM_DIR/nvm.sh" ] && \. "\$NVM_DIR/nvm.sh"

Then:

source ~/.zshrc
nvm install node

Common npm Commands

Once npm is working:

Command What it does
npm init Create a new project
npm install package Install a package locally
npm install -g package Install globally
npm uninstall package Remove a package
npm update Update packages
npm list Show installed packages
npm run script Run a script from package.json

Global vs Local Packages

Local (default): Installed in the current project's node_modules/:

npm install lodash

Global: Available anywhere on your system:

npm install -g typescript

Global packages are stored in a system location and can be run as commands.

Permission Issues with Global Installs

If you see "EACCES permission denied" when installing global packages:

Option 1: Fix npm permissions (recommended)

mkdir ~/.npm-global
npm config set prefix '~/.npm-global'
echo 'export PATH="\$HOME/.npm-global/bin:\$PATH"' >> ~/.zshrc
source ~/.zshrc

Option 2: Use npx instead

Run packages without installing:

npx create-react-app myapp

Don't use sudo with npm - it creates permission problems.

npx vs npm

npx runs a package without installing it globally:

npx create-next-app myapp    # Runs without global install
npm install -g create-next-app && create-next-app myapp  # Equivalent

npx is often cleaner.

Check npm Configuration

npm config list

Shows your npm settings, including where packages are installed.

Update npm

npm can update itself:

npm install -g npm@latest

Or through Homebrew (if that's how you installed Node):

brew upgrade node

Keep Learning

npm opens up the Node.js ecosystem. The free course covers Terminal fundamentals to help you work more efficiently.

Check it out at Mac Terminal for Humans.