On Ubuntu:
- Uninstall:
bash
sudo apt-get remove --purge nodejs npm
sudo apt-get autoremove
sudo apt-get autoclean
- Delete remaining files:
bash
sudo rm -rf /usr/local/lib/node_modules /usr/local/bin/node /usr/local/bin/npm ~/.npm
- Reinstall:
bash
curl -fsSL https://deb.nodesource.com/setup_lts.x | sudo -E bash -
sudo apt-get install -y nodejs
- Verify:
bash
node -v
npm -v
On Windows:
- Uninstall:
- Go to Control Panel > Programs > Programs and Features.
- Right-click Node.js and select Uninstall.
- Delete remaining files:
- Delete Node.js folders in
C:\Program Files\nodejs
andC:\Users\YourName\AppData\Roaming\npm
.
- Delete Node.js folders in
- Reinstall:
- Download and run the installer from Node.js website.
- Verify: Open Command Prompt or PowerShell and run:
bash
node -v
npm -v