How to Completely Uninstall and Reinstall Node.js and Related Tools on macOS
Background:
You are experiencing difficulties updating your Node.js version and encounter a persistent version mismatch between the command line and the Node Version Manager (NVM), despite installing the desired version. You aim to resolve this issue by completely removing and reinstalling Node.js and associated tools.
Solution:
Step 1: Confirm Additional Local Installation
Inspect your user directory for a "local" or "lib" folder. If present, delete any "node" or "node_modules" directories within.
Step 2: Remove Node.js Specific Directories
Step 3: Uninstall Node.js via Homebrew (If Previously Installed)
If you installed Node.js using Homebrew, execute the following command in the terminal:
brew uninstall node
Step 4: Remove NVM-Related Files
NVM may have made modifications to the PATH variable in your ".bashrc" file. Locate and revert any changes made to this file.
Step 5: Uninstall NPM
If you installed NPM separately, you can uninstall it by deleting the following directory:
~/.npm
Step 6: Uninstall Node Executable
Navigate to "/usr/local/bin" and delete any "node" executable.
Additional Cleanup (Optional):
To ensure thorough removal, you may consider running the following additional command:
sudo rm -rf /opt/local/bin/node /opt/local/include/node /opt/local/lib/node_modules sudo rm -rf /usr/local/bin/npm /usr/local/share/man/man1/node.1 /usr/local/lib/dtrace/node.d
Reinstallation:
Once everything has been removed, you can proceed with a clean installation of Node.js and related tools.
The above is the detailed content of How to Completely Uninstall and Reinstall Node.js and Associated Tools on macOS to Resolve Version Mismatches?. For more information, please follow other related articles on the PHP Chinese website!