Node.js & npm Installation Guide¶
This guide provides steps for clean installation of Node.js and npm on different operating systems.
Uninstalling Existing Installations¶
WSL Ubuntu¶
-
Remove the installed Node.js package:
sudo apt-get remove nodejs -
Remove the installed npm package:
sudo apt-get remove npm -
Remove Node.js directories:
sudo rm -rf /usr/local/lib/nodejs sudo rm -rf ~/.npm -
Check if Node.js and npm are uninstalled:
node -v npm -v -
If Node.js is still present, find and remove it:
which npm
Windows System¶
- Open the Start Menu and search for "Add or Remove Programs"
- Find Node.js in the list and click on it
- Click on the "Uninstall" button
Installing Node.js and npm using nvm¶
This is the recommended approach for all platforms:
-
Install nvm:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/install.sh | zsh -
Activate nvm:
source ~/.zshrc -
Install Node.js and npm:
nvm install node -
Verify the installation:
node -v npm -v
Fixing Permission Issues on macOS¶
If you encounter permission errors when running npm:
-
Add npm directory to PATH:
nano ~/.bash_profile -
Add this line:
export PATH="$HOME/.npm-packages/bin:$PATH" -
Save the file and verify:
cat .bash_profile -
Optional: Add nvm configuration:
export NVM_DIR=~/.nvm [ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" -
Update your environment:
source ~/.bash_profile source ~/.bashrc source ~/.zshrc