Explain Codes LogoExplain Codes Logo

How do I completely uninstall Node.js, and reinstall from beginning (Mac OS X)

javascript
prompt-engineering
interview-preparation
tools
Nikita BarsukovbyNikita Barsukov·Sep 26, 2024
TLDR

To eradicate Node.js and its traces from your Mac, run these commands:

sudo rm -rf /usr/local/bin/node /usr/local/lib/node_modules /usr/local/include/node /usr/local/share/man/man1/node.1 /usr/local/lib/dtrace/node.d

For a fresh-as-a-daisy Node.js installation, no sweat, just run:

brew install node

Like wiping out Lord Voldemort's horcruxes, this ensures a fresh start for your Node.js journey.

Uninstallation: Total annihilation

Git rid of Node.js and leftovers

Old baggage affects performance. Kick out the lurking traces of Node.js before you bring in the spanking fresh setup. Here, we're aiming for an Apollo mission, not a haunted house tour.

  • Exorcise Node if it was installed with Homebrew (the exorcism charm):
    brew uninstall node
  • Blast off directories and configurations which may have Node files and caches (like cleaning out the Room of Requirement):
    sudo rm -rf /usr/local/lib/node /usr/local/lib/node_modules /usr/local/include/node ~/.npm ~/.node-gyp /opt/local/bin/node sudo rm -rf /usr/local/bin/npm /usr/local/share/man/man1/node* /usr/local/lib/dtrace/node.d
  • Clean your system's PATH. If your .bashrc, .bash_profile, .zshrc, or .profile have traces of Node, remove these lines (men-in-black-style memory erase).

Homebrew magic for reinstallation

  • Potion check with Homebrew using brew doctor and clear the cauldron using brew cleanup --prune-prefix, ensuring the fresh potion brews perfectly.
  • Begin the magic:
    brew install node
  • Test the magic wand using these verification commands:
    node -v npm -v

Nvm: The chameleon's charm

Having a Node version manager like nvm is like Hermione's beaded bag — easy to bring in and toss out any Node.js version anytime, anywhere.

  • Summon nvm by downloading from the official source:
    curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash
  • Use nvm to fetch the latest Node.js and npm without needing Homebrew:
    nvm install node # "node" is an alias for the latest version nvm use node # Switches to the latest version
  • With nvm, you're the Doctor Who of Node.js versions. Slide back to any previous Node.js version:
    nvm uninstall <version> # Going back in time to an older version

Shifting shades with AVN

For fellow time travellers dealing with multiple Node versions, AVN (Automatic Version Switcher) is your ticket to effortless adaptation.

Inside Scoops: Tips and Tricks

Warding off installation dementors

  • To identify potential phantoms for deletion, the spell is lsbom for macOS specific files, simplifying hunting of Node.js-related files.
  • Repeat the exorcism if needed; Node.js, if installed in different ways, can be more difficult to drive out than Peeves the Poltergeist.

Post-clean-up beau geste

  • Master the cleaning charm by running brew cleanup time-to-time. It removes old potions (versions) and residues, keeping your witch's brew (Homebrew) in excellent condition.
  • For a smoother magical journey, abide by the wisdom in NVM's GitHub repository: nvm-sh/nvm.