To install npm on a Mac, install Node.js using nvm, the official macOS installer, or Homebrew, since Node.js includes npm. npm recommends a version manager such as nvm because installing global packages through a system installation can cause permissions errors. Choose a release labeled LTS when installing through nvm or the Node.js download page.
The short version
- Check first: If
node -vandnpm -vboth return version numbers, both tools are already installed. - Recommended route: Use nvm for a per-user installation with bash or zsh and Xcode Command Line Tools installed.
- Package alternative: Download the official macOS
.pkgfor a compatible LTS release to install Node.js and npm together. - Existing Homebrew users: Install the Node.js formula after completing Homebrew’s shell setup.
| Method | What you need | Main consideration |
|---|---|---|
| nvm | bash or zsh and Xcode Command Line Tools | Installs per user through a version manager |
| Official macOS installer | A Mac compatible with the selected release | Global packages can encounter permissions errors |
| Homebrew | Homebrew installed with shell setup complete | Your Mac must meet the current formula’s requirements |
Check whether Node.js and npm are already installed
Open Terminal and check Node.js first. Run the following command to see whether it returns a version number.
node -vNext, check npm with the command below. If both commands return version numbers, both tools are installed and available in your current shell.
npm -vIf either command is missing, choose an installation method below. These checks detect tools available through your current PATH, so a missing command does not establish whether an installation exists elsewhere on your Mac.
Install Node.js and npm with nvm
Use nvm for the version-manager route recommended by npm. It installs per user and works with bash or zsh on Intel and Apple silicon Macs compatible with the selected Node.js release. You need Xcode Command Line Tools installed before following these steps; if you do not have them, you can use the official macOS package instead.
For a zsh shell, prepare its startup file with the following command.
touch ~/.zshrcIf you use bash, your Mac may not have a profile file for the installer to update. Create one with the command below instead.
touch ~/.bash_profileRun the maintainer’s installation script below to install nvm. You can also get the tool from the nvm installation page.
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.8/install.sh | bashReopen Terminal after installation finishes. Check that your new shell recognizes nvm before installing Node.js.
command -v nvmOnce nvm is recognized, install an LTS release of Node.js. npm comes with that installation.
nvm install --ltsSelect the installed LTS release for use in your shell with the command below. Then check both versions using the commands under Confirm installation and fix missing commands.
nvm use --ltsUse the official macOS installer
To install through a macOS package, open the Node.js download page and choose a release labeled LTS. Your Mac must be compatible with the release you select.
On the selected release’s archive page, find Installer Packages and download the macOS .pkg. Open the downloaded package and complete installation. The official package is available for compatible Intel and Apple silicon Macs.
Open a new Terminal window when installation finishes, then run node -v and npm -v to check both versions. If you later encounter permissions errors when installing global packages, use the nvm route, which npm recommends for this reason.
Install through Homebrew
If you already use Homebrew, its Node.js formula provides the node, npm, and npx executables together. Complete Homebrew’s shell setup before proceeding, and check that your Mac meets the current formula’s requirements. The formula lists Apple silicon binary packages; if you use an Intel Mac, check compatibility before choosing this route.
To get Homebrew first, follow the installation instructions on the Homebrew website, including the shell-configuration instructions printed by its installer. Once Homebrew is ready, install Node.js with this command.
brew install nodeOpen a new Terminal window after installation completes. Run the version checks below to confirm that Node.js and npm are available.
Confirm installation and fix missing commands
In your new Terminal window, run both commands below. Each should return its own version number, confirming that both tools are installed and available through PATH.
node -v
npm -v
If nvm is not recognized immediately after installation, reopen Terminal and run command -v nvm again. If it is still missing, make sure your shell’s startup file exists, then run the installation script again. Once it is recognized, complete nvm install --lts and nvm use --lts before repeating the Node.js and npm checks.
For Homebrew, revisit the shell-configuration instructions printed by its installer if a command is missing, then open a new Terminal window. With the official package, make sure you have completed installation and opened a new Terminal window before checking again.
Update npm when you already have it
You need a working npm installation to update npm with its own command. If the command is missing, complete an installation method above first. Before updating, check that your installed Node.js release meets the requirements of the npm version you want.
With working npm and a compatible Node.js release, run the following update command. A system-installer installation may require elevated permissions; use the nvm route if global-package permissions become a problem.
npm install -g npm@latestCheck the npm version again when the update finishes. The returned version number identifies the npm release your shell is using.
npm -vFrequently Asked Questions
Can you use npm in Docker without installing it in the Mac shell?
Yes, you can use npm inside a container because the official Node.js Docker images include it. You need Docker installed and running in a compatible environment. This makes npm available inside the container without installing the command into your Mac’s host shell.
Which Node.js standalone archive matches your Mac?
Choose a macOS archive marked darwin-arm64 for Apple silicon or darwin-x64 for Intel. Your Mac must also be compatible with the selected Node.js release.
Should you use an older fnm installation script on macOS?
For a new macOS installation, use fnm’s Homebrew installation method. Its maintainer has deprecated the older direct-script installation mechanism on macOS in favor of Homebrew.
Is Volta a good choice for a new installation?
For a new installation, follow the Volta maintainers’ recommendation to use mise instead. Volta is now unmaintained, including compatibility with new operating system releases.