How to Uninstall Node.js on Mac
In this article
To uninstall Node.js on a Mac, you need to remove the Node.js binary, its global package directory, and any related configuration files. The exact steps depend on how you originally installed Node.js (via the official installer, Homebrew, or a version manager like nvm). This guide covers all three methods, plus a thorough cleanup to ensure no leftover files remain.
What You'll Need
- Administrator access to your Mac (you'll need to enter your password for some commands).
- A terminal app (Terminal is in /Applications/Utilities/).
- If you installed Node.js with Homebrew, you'll need Homebrew installed (check with
brew --version). - If you used a version manager like nvm or n, you'll need to know which one you used.
Step-by-Step
If You Installed Node.js from the Official Installer (.pkg)
- Open Terminal (found in /Applications/Utilities/).
- Remove the Node.js binary and core files by running this command:
sudo rm -rf /usr/local/bin/node /usr/local/bin/npm /usr/local/lib/node_modules /usr/local/include/node /usr/local/share/doc/node /usr/local/share/man/man1/node.1 /usr/local/share/man/man1/npm.1
Enter your password when prompted. This deletes the main Node.js executable, the npm package manager, and global modules. - Remove the Node.js uninstall script if it exists (it's usually in /usr/local/bin/). Run:
sudo rm -f /usr/local/bin/uninstall-node - Clean up user-level files. Run these commands to remove configuration and cache files from your home directory:
rm -rf ~/.npmrm -rf ~/.node-gyprm -rf ~/.node_repl_history
These delete the npm cache, native module build cache, and Node.js REPL history. - If you have any global npm packages installed, they were in /usr/local/lib/node_modules and are already removed. If you want to verify, run
node -vandnpm -v— both should return "command not found".
If You Installed Node.js with Homebrew
- Open Terminal.
- Uninstall Node.js with Homebrew by running:
brew uninstall node
This removes the node and npm binaries. - If you installed a specific version (e.g., node@14), use
brew uninstall node@14instead. - Clean up any leftover files with:
brew cleanup - Remove user-level files as in the previous method:
rm -rf ~/.npm ~/.node-gyp ~/.node_repl_history
If You Installed Node.js with a Version Manager (nvm, n, fnm)
- First, uninstall the Node.js version you're using. For nvm, run:
nvm uninstall
Replacewith the version number (e.g., nvm uninstall 18.0.0). To see all installed versions, runnvm list. - Remove the version manager itself. For nvm, delete the directory it's installed in (usually ~/.nvm):
rm -rf ~/.nvm - Remove the nvm initialization lines from your shell profile. Open your shell config file (e.g., ~/.bash_profile, ~/.zshrc, or ~/.profile) in a text editor and delete any lines containing
nvmorsource ~/.nvm/nvm.sh. - For the
nversion manager, uninstall Node withn rm, then remove thenbinary (usually in /usr/local/bin/n) and its directory (~/n). - Clean user-level files as above:
rm -rf ~/.npm ~/.node-gyp ~/.node_repl_history.
Common Mistakes
- Forgetting to remove global packages: If you only delete the node binary, global npm packages in /usr/local/lib/node_modules may remain. Always remove that directory.
- Using the wrong uninstall command for your installation method: Running
brew uninstall nodewhen you installed via the official .pkg won't work. Conversely, manually deleting /usr/local/bin/node when you used Homebrew may break Homebrew's symlinks. - Not cleaning up configuration files: Leftover ~/.npm and ~/.node-gyp files can cause confusion if you reinstall Node.js later, as they may contain cached data or settings from the old installation.
- Deleting /usr/local/bin/node when using a version manager: Version managers like nvm create symlinks to the actual node binary. Removing /usr/local/bin/node directly may not remove the actual installation and can break the version manager.
Tips
- Before uninstalling, check if any of your projects depend on Node.js globally. If you're removing Node.js to switch to a different version, consider using a version manager like nvm instead, which allows you to have multiple versions installed.
- If you're uninstalling to free up space, also check ~/.npm — it can grow large with cached packages. Removing it is safe.
- After uninstalling, restart your terminal or run
hash -rto clear the command path cache, so thatnodeornpmare not still found in the current session. - To verify a clean uninstall, run
which nodeandwhich npm— they should return no output or "node not found".
Troubleshooting
"node: command not found" but you still see node in some paths
This can happen if you have multiple installations. Check your PATH variable with echo $PATH and look for any directories that might contain node (like /usr/local/bin or ~/n/bin). Remove any remaining node binaries from those directories.
Homebrew says "node is not installed" but you know it is
Run brew list | grep node to see if node is listed. If not, it might have been installed via a different method. Try which node to see the actual path.
Permission errors when deleting files
If you get "Operation not permitted" or "Permission denied", you may need to use sudo for system-level directories like /usr/local. For user-level directories like ~/.npm, you shouldn't need sudo. If you do, check that the files are owned by you with ls -la ~/.npm.
After uninstalling, npm commands still work
This usually means npm is installed separately or there's a leftover symlink. Run which npm to see where it is. If it's in /usr/local/bin, remove it with sudo rm /usr/local/bin/npm. If it's elsewhere, remove that file or directory.
Frequently Asked Questions
Do I need to uninstall Node.js before installing a different version?
Not necessarily. Using a version manager like nvm allows you to install and switch between multiple versions without uninstalling. If you want to replace a system-wide installation with a version manager, it's cleaner to uninstall the old one first.
Will uninstalling Node.js affect my existing projects?
Your project files remain untouched. However, any global packages you installed (like gulp or nodemon) will be removed. Project-specific dependencies (in node_modules folders) are not affected, but you won't be able to run them without Node.js installed.
How do I check if Node.js is installed on my Mac?
Open Terminal and run node -v. If it returns a version number, Node.js is installed. If it says "command not found", it's not installed or not in your PATH.
What's the difference between uninstalling via Homebrew and the official installer?
Homebrew installs Node.js in its own directory and creates symlinks in /usr/local/bin. The official installer places files directly in /usr/local. The uninstall commands differ, but both remove the same core files. Choose the method that matches how you installed it.
Can I just delete the /usr/local/bin/node file?
Deleting just that file will remove the node command, but it will leave behind npm, global packages, and configuration files. It's better to follow the full uninstall steps to avoid leftovers.
Is it safe to delete ~/.npm?
Yes. ~/.npm is the npm cache directory. Deleting it only removes cached package tarballs and metadata — it does not affect your installed packages or projects. It will be recreated automatically when you use npm again.