To completely remove Node.js from your system, several steps are typically required, and the specific steps may vary depending on your operating system. Below are general guidelines for uninstalling Node.js on different operating systems:
On macOS:
-
If you installed Node.js via Homebrew, use the following command to uninstall:
shbrew uninstall node -
If installed via a package manager, remove the installation directory. By default, Node.js is installed at
/usr/local/bin/node, and npm at/usr/local/bin/npm. Use the following command to delete it:shsudo rm -rf /usr/local/{bin/{node,npm},lib/node_modules/npm,include/node,share/man/man1/node.*} -
Next, remove any residual cache files or local configurations from the system:
shsudo rm -rf ~/.npm sudo rm -rf ~/.node-gyp sudo rm -rf /opt/local/bin/node sudo rm -rf /opt/local/include/node sudo rm -rf /opt/local/lib/node_modules -
You can also verify that all files have been removed by searching for any files related to 'node' or 'npm':
shsudo find / -name node sudo find / -name npm
On Windows:
-
Open Control Panel > Programs > Programs and Features, then select Node.js from the list and click Uninstall.
-
Remove the installation directory of Node.js, typically
C:\Program Files\nodejs. -
Remove Node.js-related entries from the system PATH by editing environment variables.
-
Clear the npm cache:
shnpm cache clean --force -
Delete npm-related files and directories under the user profile:
shdel /s /q %userprofile%\AppData\Roaming\npm del /s /q %userprofile%\AppData\Roaming\npm-cache -
Use File Explorer or the command line to search and delete any remaining Node.js files.
On Linux:
-
If using a package manager like apt, yum, or dnf, use the corresponding uninstall command. For example, on Debian-based systems, use:
shsudo apt-get remove --purge nodejs npm -
Remove the installation directory and configuration files:
shsudo rm -rf /usr/local/bin/node sudo rm -rf /usr/local/bin/npm sudo rm -rf /usr/local/lib/node_modules sudo rm -rf /usr/local/include/node sudo rm -rf /usr/local/share/man/man1/node.* -
Clear npm cache and local configurations:
shsudo rm -rf ~/.npm sudo rm -rf ~/.node-gyp -
Search and delete any remaining Node.js files:
shsudo find / -name node sudo find / -name npm
After completing the above steps, Node.js should be fully removed from your system. Be cautious when running commands, particularly those with rm -rf, as they can permanently delete files and are irreversible. If unsure whether a file or directory should be deleted, verify it first.