How to Install NVM on Mac: Step-by-Step Guide
In this article
To install NVM on a Mac, open Terminal and run the official install script with curl, then add the NVM loading lines to your shell profile (zsh by default). After restarting Terminal, nvm --version should print a version number. This gives you a per-user Node.js version manager without touching system files or needing sudo for every install.
What You'll Need
- A Mac running macOS (any recent version).
- Terminal (found in Applications > Utilities).
- Command Line Tools for Xcode, which provide compilers and tools Node may need. Install them by running
xcode-select --installif you have not already. - An internet connection to download the script and Node versions.
- Basic familiarity with typing commands and editing a text file in Terminal.
- If you previously installed Node via a .pkg installer, consider removing it first to avoid conflicts (see Common Mistakes).
Step-by-Step
Open Terminal. You can use Spotlight (Command+Space) and type Terminal.
Check your shell. Run
echo $SHELL. On current macOS the default is/bin/zsh. The steps below assume zsh; if it prints/bin/bash, use~/.bash_profileinstead of~/.zshrcwherever it appears.Run the official install script. The NVM project provides a curl command on its GitHub page. Copy the current one-line command from the official repository and paste it into Terminal. It downloads the install script and runs it. Do not use sudo for this step; NVM installs into your home directory.
Add the loading lines to your shell profile. The installer usually prints two lines to add. Open your profile with a text editor, for example
nano ~/.zshrc. Add these lines near the end:
Save and exit (in nano: Control+O, Enter, Control+X).export NVM_DIR="$HOME/.nvm" [ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" [ -s "$NVM_DIR/bash_completion" ] && . "$NVM_DIR/bash_completion"Reload your shell. Either close and reopen Terminal or run
source ~/.zshrc.Verify the install. Run
nvm --version. You should see a version number, not “command not found”.Install a Node.js version. Run
nvm install --ltsfor the latest long-term support release, ornvm install nodefor the newest current release. NVM downloads and installs it under your home directory.Set a default. Run
nvm alias default --lts(or the version you installed) so new Terminal windows use it automatically. Then check withnode --versionandnpm --version.
Common Mistakes
- Using sudo with the install script or nvm commands. NVM is designed to run as your user. Sudo can create root-owned files in your home directory and break future installs.
- Forgetting to add the loading lines. If
nvmworks only in the window where you installed it, the profile lines are missing or in the wrong file. - Editing the wrong profile. zsh reads
~/.zshrc; bash reads~/.bash_profileor~/.bashrcdepending on how it is launched. Checkecho $SHELLfirst. - Leaving a system Node installed. A Node installed via the official .pkg puts binaries in
/usr/local/binthat can shadow nvm’s shims. Remove it properly (the Node project provides an uninstall script) before relying on nvm. - Assuming nvm affects GUI apps. Apps launched from Finder do not read your shell profile, so they may not see the Node version nvm manages. Use Terminal-launched tools for development.
Tips
- Keep the loading lines at the end of your profile so they run after other PATH changes.
- Use
nvm lsto see installed versions andnvm use <version>to switch per terminal session. - Create a project-level
.nvmrcfile containing a version number; thennvm usepicks it up automatically when run in that folder. - Update nvm occasionally by rerunning the official install script; it upgrades in place.
- If you use a version manager for other languages, keep their init lines separate and avoid duplicating PATH exports.
Troubleshooting
“nvm: command not found” after install. Confirm the loading lines are in the correct profile file and that you reloaded the shell. Run source ~/.zshrc manually. If you use a terminal app that starts a login shell, ensure the lines are in a file that shell reads.
The install script fails partway. Check your internet connection and that Command Line Tools are installed (xcode-select --install). Look for error text about permissions; if files in ~/.nvm are owned by root from an earlier sudo attempt, fix ownership with sudo chown -R $(whoami) ~/.nvm and rerun the installer without sudo.
Node works but npm does not, or global packages disappear after switching versions. Each Node version has its own global packages. Reinstall global tools after switching, or use nvm reinstall-packages <old-version> to copy them.
A different Node version keeps appearing. Check which node. If it points outside ~/.nvm, a system Node is taking priority. Remove the system install or adjust PATH order so nvm’s directory comes first.
Permission errors when installing global npm packages. Do not use sudo. Confirm you are using the nvm-managed npm (which npm should be under your home directory) and that the version is active.
Frequently Asked Questions
Do I need Homebrew to install nvm?
No. The official method is the curl install script. Homebrew has an nvm formula, but the NVM project recommends its own script because it manages the shell integration correctly.
Will nvm remove my existing Node installation?
No. nvm installs versions alongside whatever is already there. You may need to remove a system Node manually if it conflicts, but nvm itself does not delete it.
Why does nvm only work in some Terminal windows?
Because the loading lines are missing from the profile your shell reads, or the profile was not reloaded. Add them to ~/.zshrc (or the bash equivalent) and open a new window.
Can I use nvm with fish shell?
nvm’s script targets POSIX shells like zsh and bash. Fish users typically use a separate fish-native version manager or a compatibility wrapper; the standard nvm install steps above are for zsh and bash.
How do I uninstall nvm?
Remove the loading lines from your profile, then delete the ~/.nvm directory. This removes nvm and all Node versions it installed. Back up any global packages or project files first.
Does nvm change the Node version used by apps I open from Finder?
No. Finder-launched apps do not read your shell profile, so they use whatever Node is on the system PATH. nvm affects Terminal sessions and tools started from them.