已卸载Node但node -v仍显示版本,如何彻底移除及版本切换问题
Hey there! Let's break down your two Node.js issues step by step—they’re super common, so I’ve got straightforward fixes for you.
node -v Still Showing a Version) If you’ve uninstalled Node but node -v still spits out a version number, it means leftover files are lingering or your system’s PATH still points to an old Node installation. Here’s how to clean it up fully (focused on macOS since you mentioned Homebrew, with quick notes for other systems):
First, confirm you’ve uninstalled via Homebrew
If you used Homebrew to install Node, run these commands to ensure it’s fully removed:brew uninstall node brew cleanupIf you used version managers like
nvmornbefore, be sure to uninstall those specific versions too (e.g.,n uninstall 10.0ornvm uninstall 10.0).Delete leftover Node files and folders
Run this command to wipe common residual files:sudo rm -rf /usr/local/{bin/{node,npm},lib/node_modules/npm,lib/node,share/man/*/node.*}Also manually check and delete these directories if they exist:
/usr/local/lib/node/usr/local/lib/node_modules/usr/local/include/node~/Library/Application Support/npm~/Library/Caches/npm
Update your shell’s
PATH
Open your shell config file (either~/.bash_profile,~/.zshrc, or~/.profiledepending on which shell you use) and delete any lines that add Node-related paths toPATH. Then reload the config:source ~/.zshrc # Swap with ~/.bash_profile if you use BashVerify the cleanup
Close and reopen your terminal, then runnode -vandwhich node. If both return "command not found", you’ve successfully removed Node.
Quick notes for other systems:
- Windows: Uninstall Node via Control Panel, delete the
C:\Program Files\nodejsfolder, and remove Node entries from your systemPATH. - Linux: Use your package manager (e.g.,
sudo apt purge nodejs npm) then delete leftover files in/usr/local/lib/nodeor~/.npm.
node -v Still Showing 10.0 After brew uninstall node First, let’s diagnose the root cause: When you run brew uninstall node, it removes the Homebrew-installed Node, but your shell might be pointing to a different Node installation (like one from the official installer, nvm, or even a system-preloaded version).
To confirm where the active Node is coming from, run:
which node
This will show the file path of the Node executable your shell is using. If it’s not /usr/local/bin/node (Homebrew’s default path), that’s your culprit—you have another Node installation elsewhere.
Now, about the solution you’re referencing: Even without seeing the link, I can tell you that most valid fixes for this scenario fall into these categories, which are all reliable:
- Remove the non-Homebrew Node installation: If
which nodepoints to a path like/usr/bin/node(system Node) or anvm-managed location, uninstall that version directly. For official installer leftovers, use the full cleanup steps from the first section. Fornvm, runnvm use systemthennvm uninstall 10.0. - Adjust
PATHpriority: If the old Node’s path appears before Homebrew’s/usr/local/binin yourPATH, your shell will pick the old version first. Edit your shell config file to move/usr/local/binto the front of thePATHlist. - Clear shell cache: Sometimes your shell caches executable locations. Run
hash -rto clear this cache, then testnode -vagain.
If the solution you found includes any of these steps, it’s absolutely viable. The key is first pinpointing where the old Node lives with which node, then targeting that installation or adjusting your PATH accordingly.
Once the old version is gone, installing Node 8.9 is straightforward. I’d recommend using nvm (it makes version switching way less headache-prone):
# Install nvm first if you don't have it curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash # Then install and use Node 8.9 nvm install 8.9 nvm use 8.9
Or if you prefer Homebrew:
brew install node@8.9 brew link --force node@8.9
内容的提问来源于stack exchange,提问作者Neer Patel

