Okay, great! Knowing how Node.js was installed is the most important first step. Here's a breakdown by operating system and common installation methods:
First: How did you install Node.js?
- Official Installer? (.msi on Windows, .pkg on macOS)
- Package Manager? (Homebrew on macOS, Chocolatey/Scoop on Windows, apt/yum/dnf on Linux)
- Version Manager? (NVM, NVM-Windows, Volta, FNM)
- Manually from source/binary? (Less common for general users)
I. Uninstalling Node.js on Windows
A. If installed via the Official .msi Installer:
- Open "Apps & features" (or "Programs and Features" in older Windows):
- Press
Windows Key + X and select "Apps & features" or "Installed apps".
- Alternatively, search for "Add or remove programs" in the Start Menu.
- Find Node.js: Scroll through the list and find "Node.js".
- Uninstall: Select it and click "Uninstall". Follow the prompts.
- Manual Cleanup (Important - Do these even after using the uninstaller):
- Delete installation folder: Usually
C:\Program Files\nodejs. Delete this folder if it still exists.
- Delete npm folders:
C:\Users\<your_username>\AppData\Roaming\npm (This is where global packages are installed)
C:\Users\<your_username>\AppData\Roaming\npm-cache (The npm cache)
- You might need to show hidden files in File Explorer to see
AppData.
- Delete user config:
C:\Users\<your_username>\.npmrc (if it exists)
- Check Environment Variables:
- Search for "environment variables" in the Start Menu and select "Edit the system environment variables".
- Click the "Environment Variables..." button.
- Under "System variables", check if
NODE_PATH exists and delete it.
- Under "User variables" AND "System variables", select the
Path variable, click "Edit...", and remove any entries pointing to nodejs or npm (e.g., C:\Program Files\nodejs\, C:\Users\<your_username>\AppData\Roaming\npm). Be careful not to delete other important paths.
B. If installed via NVM-Windows:
- List installed versions: Open Command Prompt or PowerShell (as Administrator) and run:
nvm list
- Uninstall specific versions:
nvm uninstall <version_number>
For example: nvm uninstall 18.12.0
To uninstall all Node versions managed by nvm-windows: nvm uninstall all (use with caution).
- Uninstall NVM-Windows itself:
- Go to "Apps & features" (as described in section A1).
- Find "NVM for Windows" and uninstall it.
- Manual Cleanup for NVM-Windows:
- Delete the NVM installation directory (usually
C:\Users\<your_username>\AppData\Roaming\nvm or wherever you specified during install).
- Delete the Node.js symlink directory (usually
C:\Program Files\nodejs).
- Check Environment Variables (as in A4) for
NVM_HOME and NVM_SYMLINK and remove them, and also clean up Path entries related to NVM.
C. If installed via Chocolatey:
- Open PowerShell (as Administrator).
- Run:
choco uninstall nodejs
# or to be more specific if you installed a particular version like nodejs-lts
# choco uninstall nodejs-lts
- Chocolatey usually does a good job cleaning up, but you can double-check the manual cleanup steps in section A4 if you want to be thorough.
D. If installed via Scoop:
- Open PowerShell.
- Run:
scoop uninstall node
- Scoop also typically cleans up well.
II. Uninstalling Node.js on macOS
A. If installed via the Official .pkg Installer:
This is the trickiest because the official installer spreads files around and doesn't provide a simple uninstaller. You'll need to use Terminal with sudo.
Be very careful with sudo rm -rf commands. A typo can delete important system files.
Open Terminal and run the following commands one by one:
sudo rm -rf /usr/local/lib/node
sudo rm -rf /usr/local/lib/node_modules
sudo rm -rf /usr/local/include/node
sudo rm -rf /usr/local/include/node_modules
sudo rm /usr/local/bin/node
sudo rm /usr/local/bin/npm # if it exists
sudo rm /usr/local/bin/npx # if it exists
sudo rm -rf /usr/local/share/man/man1/node.1
sudo rm -rf /usr/local/lib/dtrace/node.d
# Clean up user-specific npm files
rm -rf ~/.npm
rm -rf ~/.node-gyp
rm -f ~/.npmrc # if it exists
# Potentially remove receipts (use with caution, make sure you only target nodejs ones)
# ls /var/db/receipts/ | grep node
# If you see org.nodejs.pkg or similar, you can remove them:
# sudo rm /var/db/receipts/org.nodejs.*
You might also need to remove Node from your shell's PATH if it was added manually (e.g., in ~/.bash_profile, ~/.zshrc, ~/.bashrc, ~/.profile).
B. If installed via Homebrew:
- Open Terminal.
- Run:
brew uninstall node
brew cleanup # Removes old versions and other cruft
- Homebrew usually handles this cleanly.
C. If installed via NVM (Node Version Manager):
- Open Terminal.
- Deactivate current version (if active):
nvm deactivate
- Uninstall specific Node versions:
nvm uninstall <version_number>
# e.g., nvm uninstall 18.12.0
# To uninstall the currently active version (after deactivating):
# nvm uninstall node
- To uninstall NVM itself:
- Remove the NVM lines from your shell configuration file (
~/.bash_profile, ~/.zshrc, ~/.bashrc, or ~/.profile). These lines usually look like:
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion
- Delete the NVM directory:
rm -rf ~/.nvm
- Remove any NVM-related user files:
rm -rf ~/.npm # if you only used npm through NVM-managed Node
rm -rf ~/.node-gyp # if you only used it through NVM-managed Node
III. Uninstalling Node.js on Linux
A. If installed via a Package Manager (apt, yum, dnf):
- For Debian/Ubuntu (apt):
Open Terminal and run:
sudo apt-get purge nodejs npm
sudo apt-get autoremove
# Sometimes node is installed as 'node' not 'nodejs'
# sudo apt-get purge node npm
- For CentOS/RHEL/Fedora (yum/dnf):
Open Terminal and run:
sudo yum remove nodejs npm # For older systems
# OR
sudo dnf remove nodejs npm # For newer Fedora/RHEL
- Manual Cleanup (Optional but recommended):
rm -rf ~/.npm
rm -rf ~/.node-gyp
# Check for leftovers in /usr/local/lib/node_modules or /usr/lib/node_modules
# sudo rm -rf /usr/local/lib/node_modules # (if it exists and you're sure)
# sudo rm -rf /usr/lib/node_modules # (if it exists and you're sure)
B. If installed via NVM (Node Version Manager):
Same steps as for macOS NVM (Section II.C).
C. If installed manually (from source or binary tarball):
- You need to remember where you installed it (e.g.,
/usr/local/, /opt/, or your home directory).
- Typically, you'd delete the following from the installation prefix:
sudo rm -rf <prefix>/lib/node
sudo rm -rf <prefix>/lib/node_modules
sudo rm -rf <prefix>/include/node
sudo rm -rf <prefix>/include/node_modules
sudo rm <prefix>/bin/node
sudo rm <prefix>/bin/npm
sudo rm <prefix>/bin/npx
(Replace <prefix> with your actual installation path, e.g., /usr/local).
- Clean up user-specific files:
rm -rf ~/.npm
rm -rf ~/.node-gyp
- Remove any PATH modifications from your shell configuration files.
IV. After Uninstalling (All Systems)
- Close and reopen your Terminal/Command Prompt/PowerShell. This is crucial for PATH changes to take effect.
- Verify uninstallation:
node -v
npm -v
npx -v
These commands should now result in "command not found" or a similar error.
- Restart your computer (Optional but recommended): This ensures any processes still using the old Node installation are terminated.
Choose the section that matches your OS and installation method. If you're unsure how it was installed, try the "Official Installer" method for your OS first, then check for NVM. Good luck!