How to Uninstall and Reinstall Node.js and npm

ยท updated ยท post node.js npm guide

Guide to Uninstalling and Reinstalling Node.js and npm

Node.js is an essential runtime for JavaScript, and npm (Node Package Manager) is its package manager. However, there are times when you need to completely uninstall and reinstall Node.js and npm, whether due to version conflicts, broken installations, or upgrading to a newer version.

This guide will cover three different methods to uninstall and reinstall Node.js and npm on Windows, macOS, and Linux.


๐Ÿ›  Method 1: Uninstall & Reinstall Node.js and npm Manually

If you installed Node.js via the official installer or a package manager other than nvm or brew, youโ€™ll need to manually remove it.

๐Ÿ”น Windows (Manual Uninstallation)

Uninstall Node.js

  1. Open Control Panel โ†’ Programs โ†’ Programs and Features.
  2. Find Node.js in the list.
  3. Click Uninstall and follow the prompts.

Remove npm Cache & Environment Variables

  1. Delete the global npm modules:

    rd /s /q "%AppData%\npm"
    rd /s /q "%AppData%\npm-cache"
  2. Remove Node.js from System Environment Variables:

    • Press Win + R, type sysdm.cpl, and hit Enter.
    • Go to the Advanced tab and click Environment Variables.
    • Under System Variables, find NODE_PATH, select it, and click Delete.
    • Look for Path, edit it, and remove any reference to Node.js.

Verify Node.js Removal

Run the following in PowerShell or CMD:

node -v
npm -v

If it returns "command not found", Node.js has been successfully removed.


๐Ÿ”น macOS (Manual Uninstallation)

Remove Node.js and npm

  1. Open Terminal and run:

    sudo rm -rf /usr/local/bin/node
    sudo rm -rf /usr/local/include/node
    sudo rm -rf /usr/local/lib/node_modules
  2. Remove npm cache:

    rm -rf ~/.npm
    rm -rf ~/.node-gyp
  3. If you installed Node.js using the .pkg file, you can also remove it via:

    sudo rm -rf /usr/local/lib/dtrace/node.d

Verify Uninstallation

node -v
npm -v

If they are no longer recognized, Node.js is fully removed.


๐Ÿ”น Linux (Manual Uninstallation)

Remove Node.js and npm

  1. Run the following command:

    sudo apt-get remove --purge nodejs npm
  2. Clean up global npm packages:

    sudo rm -rf /usr/local/lib/node_modules
    rm -rf ~/.npm

Verify Uninstallation

node -v
npm -v

๐Ÿ›  Method 2: Uninstall & Reinstall Node.js via Homebrew (macOS & Linux)

If you installed Node.js via Homebrew, you can easily uninstall and reinstall it.

๐Ÿ”น Uninstall Node.js using Homebrew

  1. Open Terminal and run:

    brew uninstall node
  2. Clean up leftover files:

    brew cleanup

Verify Node.js Removal

node -v
npm -v

If Node.js is not found, it has been successfully removed.


๐Ÿ”„ Reinstall Node.js using Homebrew

To reinstall:

brew install node

After installation, verify:

node -v
npm -v

๐Ÿ›  Method 3: Uninstall & Reinstall Node.js using nvm (Node Version Manager) (My Personal Preference)

If you installed Node.js using nvm, this is the easiest way to manage multiple Node.js versions. The link to the source code can be found here: nvm-sh/nvm.

๐Ÿ”น Uninstall Node.js using nvm

  1. Open Terminal (or PowerShell for Windows).

  2. Run the following command:

    nvm uninstall <version>

    Replace <version> with the installed Node.js version. You can check installed versions with:

    nvm ls
  3. To completely remove nvm (optional), delete its directory:

    rm -rf ~/.nvm

๐Ÿ”„ Reinstall Node.js using nvm

  1. First, make sure nvm is installed:

    curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.1/install.sh | bash

    If you are like me and have some problems with the PATH of your nvm installation, run the following command (from the source repository):

    export NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ] && printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm")"
    [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
  2. Reload your shell configuration:

    source ~/.zshrc  # For macOS/Linux (zsh users)
    source ~/.bashrc  # For Linux/macOS (bash users)
  3. Install the latest LTS version of Node.js:

    nvm install --lts
  4. Verify installation:

    node -v
    npm -v

๐ŸŽฏ Summary of Uninstallation & Reinstallation Methods

Method Windows macOS Linux
Manual Control Panel โ†’ Remove Node.js, delete cache rm -rf Node files apt-get remove
Homebrew โŒ Not available brew uninstall node brew uninstall node
nvm nvm uninstall <version> nvm uninstall <version> nvm uninstall <version>

๐Ÿš€ Which Method Should You Use?


๐Ÿ’ก Final Thoughts

Now you know how to completely uninstall and reinstall Node.js and npm using three different methods across Windows, macOS, and Linux. Using nvm is generally the best option for developers as it allows you to switch between different Node.js versions easily.

Let me know if you run into any issues! ๐Ÿš€

TL;DR