A clean uninstall and reinstall of Node.js and npm on macOS fixes broken PATH entries, version conflicts, and permission errors. Because macOS setups often mix Homebrew, the official .pkg installer, or version managers, removing leftover binaries and caches is essential before starting fresh.
1. Remove Existing Node.js and npm Installations
Run the steps that match how Node.js was installed on your Mac, then clear out global modules and caches:
-
If installed via Homebrew: Uninstall Node and prune old links/files:
brew uninstall --force node brew cleanup
-
If installed via the official
.pkginstaller: Remove the installed binaries, libraries, man pages, and package receipts:sudo rm -rf /usr/local/{lib/node{,/.npm,_modules},bin,share/man}/{npm*,node*,man1/node*} sudo rm -rf /usr/local/lib/dtrace/node.d sudo pkgutil --forget org.nodejs.node.pkg sudo pkgutil --forget org.nodejs.npm.pkg
-
Clear npm caches and leftover state: Remove user-level caches and history directories:
rm -rf ~/.npm ~/.node-gyp ~/.node_repl_history
-
Verify removal: Open a fresh terminal window and check that
nodeandnpmare no longer found (which nodeshould return nothing or show a version manager path you intend to keep).
2. Reinstall Node.js and npm Cleanly
Pick a clean installation method depending on whether you want a single system install or multiple Node versions per project:
-
Option A — Homebrew (simple single-version setup): Install the
nodeformula (which bundlesnpm) and verify the versions:brew install node node -v npm -v
-
Option B — Version manager (
nvmorfnm): Ideal if you switch Node versions across projects without hitting global permission issues. After installing your chosen version manager and restarting your shell, install the latest LTS release:nvm install --lts nvm use --lts node -v npm -v
3. Common Gotchas After Reinstalling
- Stale
PATHentries in shell config: Check~/.zshrc(or~/.bash_profile) for old manualPATHexports pointing to deleted Node folders so your shell resolves the new binary cleanly. - Global packages are not carried over: Anything you previously installed with
npm install -gwill need to be reinstalled after a clean wipe. - Apple Silicon vs. Intel Homebrew paths: On Apple Silicon Macs, Homebrew lives under
//homebrew, whereas Intel Macs use/usr/local—avoid mixing old/usr/localNode leftovers with//homebrewpaths.
TL;DR: Remove Node via Homebrew or .pkg cleanup, delete ~/.npm and ~/.node-gyp caches, reinstall via Homebrew (brew install node) or a version manager (nvm install --lts), and verify with node -v and npm -v in a fresh terminal.
Did you originally install Node via Homebrew, the official .pkg installer, or a version manager like nvm?
