Removing Node.js from your Mac is more involved than dragging an app to the Trash because it installs files in several system locations. This guide walks you through three reliable methods: using the official installer’s uninstall script, manually deleting all related files, or using a package manager like Homebrew. You’ll also learn how to verify the removal and avoid common pitfalls.
What You’ll Need
- Administrator access to your Mac (you’ll need to enter your password for sudo commands).
- Terminal app (found in /Applications/Utilities/).
- If you installed Node.js with a package manager, know which one you used (Homebrew, MacPorts, or nvm).
Step-by-Step
Method 1: Using the Official Uninstall Script (if you used the .pkg installer)
- Open Terminal (⌘+Space, type “Terminal”, press Enter).
- Run the following command to download the uninstall script from the Node.js GitHub repository:
curl -o uninstall-node.sh https://raw.githubusercontent.com/nodejs/help/master/remove_node.sh - Make the script executable:
chmod +x uninstall-node.sh - Run the script with sudo:
sudo ./uninstall-node.sh - Enter your admin password when prompted. The script will remove Node.js and npm files from /usr/local/bin, /usr/local/lib, and other common locations.
- After it finishes, delete the script:
rm uninstall-node.sh
Method 2: Manual Removal (works for any installation)
- Open Terminal.
- Remove the main Node.js binary and npm symlinks. Run these commands one by one:
sudo rm -f /usr/local/bin/nodesudo rm -f /usr/local/bin/npmsudo rm -f /usr/local/bin/npx - Remove the Node.js and npm directories from /usr/local/lib:
sudo rm -rf /usr/local/lib/node_modulessudo rm -rf /usr/local/lib/node - Remove the include directory:
sudo rm -rf /usr/local/include/node - Remove any global npm packages (if you had any installed globally, they live in /usr/local/lib/node_modules, which you already removed).
- Remove configuration and cache files in your home directory:
rm -rf ~/.npmrm -rf ~/.node-gyprm -rf ~/.node_repl_history - If you used Homebrew, also run:
brew uninstall node(if it was installed via Homebrew) andbrew cleanup.
Method 3: Using Homebrew (if installed via Homebrew)
- Open Terminal.
- Run:
brew uninstall node - If you want to remove all unused dependencies, run:
brew autoremove - Optionally, clean up the Homebrew cache:
brew cleanup
Common Mistakes
- Only deleting the node binary: Many files remain in /usr/local/lib and ~/.npm, leaving broken references.
- Not using sudo: System directories are protected; without sudo, commands fail with “Permission denied”.
- Forgetting about nvm: If you used nvm, you need to remove its directory (~/.nvm) and the lines in your shell profile (like .zshrc or .bash_profile) that load it.
- Ignoring npm global packages: They are inside /usr/local/lib/node_modules, so removing that directory removes them all.
Tips
- Before uninstalling, check if any projects depend on Node.js. You can list global packages with
npm list -g --depth=0to see what you might want to reinstall later. - Use
which nodeandwhich npmto confirm the exact paths before deleting files. - If you plan to reinstall later, consider using nvm (Node Version Manager) to manage multiple versions easily.
- After removal, close and reopen Terminal to ensure the shell picks up the changes.
Troubleshooting
“node: command not found” after uninstall: This is expected if the removal worked. If you still see this after reinstalling, your shell might be caching the old path—run hash -r or restart Terminal.
Permission errors during manual removal: Make sure you’re using sudo for system directories. For home directory files, you don’t need sudo.
Can’t find some files: If you used a version manager like nvm, files are in ~/.nvm, not in /usr/local. Remove that directory and edit your shell profile to remove the nvm initialization lines.
npm still works after removing node: This can happen if npm is installed as a separate package (e.g., via Homebrew). Uninstall it with brew uninstall npm (if that’s the case).
After uninstalling, Terminal shows a warning about missing node: This may come from a shell script (like .zshrc) that references node. Edit that file and remove the line.
Frequently Asked Questions
Do I need to uninstall Node.js before installing a new version?
Not necessarily. You can use nvm to switch versions, or install a new version over the old one, but it’s cleaner to uninstall first to avoid conflicts.
Will uninstalling Node.js delete my projects?
No, your project files (like package.json, source code) are separate. Only global npm packages and the Node.js runtime are removed.
What is the difference between npm and Node.js?
Node.js is the runtime that executes JavaScript; npm is the package manager that installs libraries. They are usually installed together, but you can remove them separately.
How do I know if Node.js was installed via Homebrew or the installer?
Run which node. If it shows /usr/local/bin/node, it could be either. Check with brew list node—if it lists, it was Homebrew. Also, the installer typically puts files in /usr/local, while nvm uses ~/.nvm.
Is it safe to delete the ~/.npm folder?
Yes, it only contains cache and logs. Deleting it frees space and doesn’t affect your projects.
What if I can’t find the uninstall script?
You can always use the manual method—it works for any installation. Just follow the steps carefully.
Related
Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.
More cards in this drawer
- Channel TLD Websites: What They Are & How to Get One5.00 min/km
- Django Class Based Views CRUD REST API
- Most Secure OS for Privacy: 3 Picks by Device
- Ryobi One+ Battery System: Is the Switch Worth It?
- Tmux Terminal Upgrade: Is It Worth It?
- Refurbished Tech Buying Checklist