How do I completely uninstall Node.js and reinstall from scratch on Mac OS X?
I’m experiencing an issue where my Node.js version remains at v0.6.1-pre despite attempts to update it using Homebrew and NVM. When I check my Node version with node -v, it shows:
v0.6.1-pre
NVM initially shows the correct version after installation in a bash terminal:
nvm ls
v0.6.19
current: v0.6.19
However, after restarting bash, NVM shows:
nvm ls
v0.6.19
current: v0.6.1-pre
default -> 0.6.19 (-> v0.6.19)
I’ve tried several troubleshooting steps:
- Using Homebrew to update and install Node (
brew updateandbrew install node) - Deleting the “node” directory in
/usr/local/include - Deleting “node” and “node_modules” in
/usr/local/lib - Following instructions to uninstall and reinstall npm
Despite these attempts, the Node version remains outdated, and I’m unable to install libraries like “zipstream” via NPM. I would like to completely uninstall Node.js, npm, and NVM, then reinstall everything from scratch on my system.
To completely uninstall Node.js, npm, and NVM from your Mac OS X system and reinstall from scratch, you’ll need to perform a thorough cleanup that removes all traces of these tools, then follow a clean installation process. The issue you’re experiencing with the persistent v0.6.1-pre version typically occurs when multiple installations exist and the system is finding the wrong one in your PATH.
Contents
- Complete Node.js Uninstallation
- Complete NVM Removal
- Complete NPM Cleanup
- Verifying Complete Removal
- Clean Installation Process
- Verifying the New Installation
- Troubleshooting Common Issues
Complete Node.js Uninstallation
Start with completely removing Node.js, regardless of how it was originally installed:
Method 1: If installed via Homebrew
brew uninstall node brew cleanup
Method 2: Manual cleanup for all installations
Run these commands to remove all traces of Node.js from your system:
# Remove Node.js binaries
sudo rm -rf /usr/local/bin/node
sudo rm -rf /usr/local/bin/npm
sudo rm -rf /usr/local/bin/npx
# Remove Node.js headers and libraries
sudo rm -rf /usr/local/include/node
sudo rm -rf /usr/local/lib/node_modules
sudo rm -rf /usr/local/share/doc/node
sudo rm -rf /usr/local/share/man/man1/node.1
sudo rm -rf /usr/local/share/systemtap/tapset/node.stp
# Remove other Node.js related files
sudo rm -rf /usr/local/lib/dtrace/node.d
Method 3: Check for additional installations
Node.js might be installed in other locations. Check these common paths:
# Check for Node in common locations
which node
ls -l /usr/local/bin/node
ls -l /opt/local/bin/node # MacPorts
ls -l /usr/local/bin/node # Homebrew
# Remove any found binaries
sudo rm -f /opt/local/bin/node
Important: Remove all instances of Node.js you find, not just one. The issue you’re experiencing is likely due to multiple installations conflicting with each other.
Complete NVM Removal
NVM (Node Version Manager) needs to be completely removed to avoid conflicts:
Step 1: Remove NVM directory
# First, deactivate NVM if active
nvm deactivate 2>/dev/null || true
# Remove the NVM directory
rm -rf ~/.nvm
rm -rf ~/.nvm_node
Step 2: Remove NVM from shell configuration
NVM adds configuration lines to your shell profile files. You need to remove them:
For Zsh users (default in recent macOS):
# Check if NVM is in .zshrc
grep -n "nvm" ~/.zshrc
# Remove NVM lines (usually the last 3-4 lines)
# Edit the file to remove these lines:
# export NVM_DIR="$HOME/.nvm"
# [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
# [ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"
For Bash users:
# Check if NVM is in .bash_profile or .bashrc
grep -n "nvm" ~/.bash_profile ~/.bashrc
# Remove NVM lines from the appropriate file
Step 3: Update PATH
After editing your shell configuration, restart your terminal or run:
source ~/.zshrc # or source ~/.bash_profile
Complete NPM Cleanup
Remove all npm-related files and configurations:
# Remove npm global packages and cache
npm uninstall -g npm
npm cache clean --force
# Remove npm directories
rm -rf ~/.npm
rm -rf ~/.node-gyp
rm -rf ~/.nodereplhistory
rm -rf ~/.npmrc # This is npm's configuration file
# Remove npm from system paths
sudo rm -f /usr/local/bin/npm
sudo rm -f /usr/local/bin/npx
Verifying Complete Removal
Before reinstalling, verify that all traces of Node.js, npm, and NVM have been removed:
# Check for any remaining Node.js installations
which node
node -v
npm -v
nvm --version
# Check for Node.js files in common locations
ls -la /usr/local/bin/node* 2>/dev/null || echo "No Node.js binaries found"
ls -la /usr/local/lib/node_modules 2>/dev/null || echo "No Node.js modules found"
ls -la ~/.nvm 2>/dev/null || echo "No NVM directory found"
# Check shell configuration for NVM references
grep -i "nvm" ~/.zshrc ~/.bash_profile ~/.bashrc || echo "No NVM references found"
All these commands should show either “No…” messages or no output at all. If any Node.js, npm, or NVM commands still work, you need to continue the cleanup process.
Clean Installation Process
Once you’ve verified complete removal, install everything fresh:
Step 1: Install NVM (recommended)
# Install NVM using the official installer
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bash
# Activate NVM in your current session
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"
# Verify NVM installation
nvm --version
Step 2: Install Node.js using NVM
# Install the latest LTS version of Node.js
nvm install --lts
# Set the LTS version as default
nvm alias default node
# Or install a specific version if needed
# nvm install 18.17.0
# nvm alias default 18.17.0
Step 3: Verify Node.js installation
# Check Node version
node -v
# Check npm version
npm -v
# List installed Node versions
nvm ls
Verifying the New Installation
Test your fresh installation to ensure everything works correctly:
# Test Node.js
node -e "console.log('Node.js is working! Node version:', process.version)"
# Test npm
npm install -g express-generator
npx express-generator --help
# Test NVM version switching
nvm install 16.20.0
nvm use 16.20.0
node -v
nvm use default
node -v
Troubleshooting Common Issues
Issue: Still seeing old Node version
If you’re still seeing the old version after following these steps:
# Check all locations where Node might be installed
find /usr/local -name "node" -type f 2>/dev/null
find /opt -name "node" -type f 2>/dev/null
find /usr -name "node" -type f 2>/dev/null
# Check your PATH order
echo $PATH | tr ':' '\n' | grep -E "(node|nvm)"
# Restart your computer to ensure all processes are cleared
Issue: npm permissions errors
# Fix npm permissions (if needed)
mkdir ~/.npm-global
npm config set prefix '~/.npm-global'
# Add to your shell profile:
echo 'export PATH=~/.npm-global/bin:$PATH' >> ~/.zshrc
source ~/.zshrc
Issue: NVM not working after reinstallation
# Ensure NVM is properly sourced in your shell config
echo 'export NVM_DIR="$HOME/.nvm"' >> ~/.zshrc
echo '[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"' >> ~/.zshrc
echo '[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"' >> ~/.zshrc
source ~/.zshrc
Conclusion
- Complete cleanup requires removing all traces of Node.js, npm, and NVM from multiple locations including system directories, user directories, and shell configuration files
- Multiple installations often cause conflicts - the v0.6.1-pre version you’re seeing likely comes from an old installation that’s being found first in your PATH
- NVM provides version management but needs to be completely removed and reinstalled to avoid conflicts
- Verification steps are crucial - always check that everything is properly removed before reinstalling
- Clean installation using NVM is the recommended approach for managing multiple Node.js versions on macOS
For your specific issue with the outdated v0.6.1-pre version, following this complete uninstallation and reinstallation process should resolve the problem. The key is ensuring that absolutely no traces of the old installation remain anywhere on your system.
Sources
- How to completely uninstall Node.js and reinstall from beginning (Mac OS X)
- How to Uninstall Node Using NVM and from Mac
- How to Uninstall Node.js on Mac using Homebrew: A Step-by-Step Guide
- How to Completely Uninstall Node on Mac (Node.js and NPM)
- How to Uninstall NVM?
- How to completely uninstall NVM in macOS