MacOS下如何卸载所有Node版本(含brew安装版)及解决版本异常
Let’s walk through your questions one by one—this is a super common pain point when you’ve installed Node via multiple methods (official installer, Homebrew, nvm, etc.) on macOS.
Why does node --version conflict with which node?
The most likely culprit is shell command caching (the shell’s hash table). When you first run node, your shell scans your PATH to find the executable, then stores that path in a cache to speed up future calls. If you later modify your PATH (e.g., install nvm which adds a new Node path to the front) or delete/move the original Node binary, the shell might still use the cached path instead of re-scanning PATH.
Another possibility is if you’re using a version manager like nvm or volta: these tools often use "shims" that intercept the node command to point to their managed versions. In this case, which node might find the system-level binary at /usr/local/bin/node, but the shim is redirecting node --version to a different version (your 8.x install) that’s not detected by which.
Can I directly delete /usr/local/bin/node?
Absolutely—with a few caveats:
- If this binary was installed via the official Node package, Homebrew, or manually, deleting it is safe. Just make sure no critical system tools depend on it (this is rare for Node, as most macOS system processes don’t rely on user-installed Node versions).
- First, check if it’s a symlink (common with Homebrew) by running
ls -l /usr/local/bin/node. If it points to a Homebrew Cellar path, deleting it is fine—Homebrew will clean up the rest if you runbrew uninstall nodefirst. - If it’s a standalone binary, deleting it removes that specific Node version from your system-level
PATH.
How to completely uninstall all Node.js versions?
To wipe every trace of Node from your system, follow these steps based on how you installed it:
1. Clear shell cache first
Run this to reset your shell’s command cache, so it stops using outdated paths:
hash -r
2. Uninstall version manager installations (nvm, n, volta)
- For nvm:
- To delete all managed Node versions:
nvm uninstall --all - To remove nvm entirely:
Then open your shell config file (rm -rf ~/.nvm~/.bashrc,~/.zshrc, or~/.profile) and delete any lines related to nvm (e.g.,export NVM_DIR=...orsource ~/.nvm/nvm.sh).
- To delete all managed Node versions:
3. Uninstall Homebrew-installed Node
brew uninstall node brew cleanup
4. Remove system-level/official installer traces
Run these commands to delete leftover files from official packages or manual installs:
# Delete core binaries and npm sudo rm -rf /usr/local/{bin/{node,npm},lib/node_modules/npm,lib/node,share/man/*/node.*} # Delete user-specific configs and caches rm -rf ~/.npm rm -rf ~/.node-gyp rm -rf /Library/Preferences/com.nodejs.plist rm -rf /Library/Application Support/node rm -rf /Library/Caches/node
5. Verify the uninstall
After completing the above steps, run these commands to confirm Node is gone:
node --version # Should return "command not found" which node # Should also return "node not found" echo $PATH | grep node # Should show no Node-related paths (remove any leftover entries from your shell config if needed)
Once you’re done, you can start fresh with a clean Node setup—using a version manager like nvm is highly recommended to avoid this kind of chaos in the future!
内容的提问来源于stack exchange,提问作者kramer65

