How to Uninstall Node.js and npm: Step-by-Step Guide

Node.js is a widely used runtime environment for building server-side applications using JavaScript. However, there are situations where you might want to remove it entirely from your computer, whether to troubleshoot an issue, switch to a different version, or just free up space. In this article, I’ll guide you through the process of completely uninstalling Node.js from your system.

The uninstallation process varies depending on the operating system you are using (Windows, macOS, or Linux). Below, we will cover the steps for all three major platforms.

Uninstalling Node.js on Windows

Step 1: Uninstall Node.js from Programs and Features

  1. Open the Start Menu and search for “Control Panel.”
  2. In the Control Panel, go to Programs and then Programs and Features.
  3. Scroll down the list of installed programs until you find Node.js.
  4. Right-click on Node.js and select Uninstall.
  5. Follow the on-screen instructions to complete the uninstallation.

Step 2: Delete Remaining Files

Node.js might leave some configuration files and folders even after uninstallation. To ensure everything is removed:

  1. Press Windows + R to open the Run dialog.
  2. Type %appdata% and hit Enter.
  3. Delete any folders related to npm or Node.js in the directory (typically found under C:\Users\<Your Username>\AppData\Roaming).

Step 3: Remove Environment Variables

  1. Open the Start Menu, search for “Environment Variables,” and select Edit the system environment variables.
  2. In the System Properties window, click on Environment Variables.
  3. Look for Node.js or npm entries under System variables or User variables.
  4. Select them and click Delete.

Step 4: Check Node.js and npm Are Completely Removed

To verify that Node.js and npm are gone, open Command Prompt or PowerShell and run the following commands:

node -v
npm -v

If the command is not recognized, the removal was successful.

Uninstalling Node.js on macOS

Step 1: Uninstall Node.js Using Homebrew (If Installed via Homebrew)

If you installed Node.js via Homebrew, you can remove it using the following commands in Terminal:

  1. Open Terminal.
  2. Run the following command to uninstall Node.js:
brew uninstall node
  1. If you want to remove any unused dependencies left by Node.js, run:
brew cleanup

Step 2: Manually Remove Node.js (If Installed Manually)

If you installed Node.js manually (without Homebrew), you will need to remove it manually:

  1. Open Terminal.
  2. Run the following commands to delete the Node.js installation and its symlinks:
sudo rm -rf /usr/local/bin/node
sudo rm -rf /usr/local/lib/node_modules
sudo rm -rf /usr/local/include/node
sudo rm -rf /usr/local/bin/npm

Step 3: Remove npm Global Packages and Cache

To completely clean up any npm-related files:

  1. Remove the global npm packages and npm cache:
sudo rm -rf ~/.npm
sudo rm -rf /usr/local/lib/node_modules

Step 4: Verify Node.js and npm Removal

To confirm that Node.js and npm are completely removed, run the following commands in Terminal:

node -v
npm -v

If both commands return errors, Node.js has been successfully removed.

Uninstalling Node.js on Linux (Ubuntu/Debian-Based Distros)

Step 1: Uninstall Node.js

If you installed Node.js via a package manager (like apt or n), you can uninstall it as follows:

  1. Open your Terminal.
  2. If you installed Node.js using apt, run:
sudo apt-get remove --purge nodejs
sudo apt-get autoremove

Step 2: Manually Remove Node.js

If there are any Node.js files left, manually delete them by running:

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

Step 3: Verify Node.js Removal

To ensure that Node.js and npm have been completely removed, you can run:

node -v
npm -v

If the commands return “command not found,” Node.js has been completely removed from your system.

Optional: Removing Node Version Manager (nvm)

In some cases, you might have installed Node.js using nvm (Node Version Manager). nvm allows you to install multiple versions of Node.js and switch between them. Here’s how to remove nvm and all installed Node.js versions for each operating system:

Removing nvm on macOS and Linux:

  1. Open Terminal.
  2. Remove nvm by deleting the nvm directory:
rm -rf ~/.nvm
  1. Remove the following lines from your shell’s configuration file (~/.bashrc, ~/.zshrc, or ~/.profile):
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"  # This loads nvm
  1. Reload the terminal.
  1. Verify that nvm is no longer available by running:
nvm --version

If it returns “command not found,” nvm has been successfully removed.

Removing nvm on Windows:

If you installed nvm for Windows (commonly referred to as nvm-windows), follow these steps:

  1. Open Control Panel and go to Programs and Features.
  2. Find nvm in the list, right-click, and select Uninstall.
  3. Additionally, check if there are any environment variables pointing to nvm by:
    • Right-clicking on This PC or Computer and selecting Properties.
    • Go to Advanced system settings and click Environment Variables.
    • Remove any entries related to nvm.

After this, Node.js versions managed by nvm should also be removed. You can confirm by running node -v in the Command Prompt.

Conclusion

By following the steps outlined in this guide, you can completely remove Node.js from your system, along with any associated files and environment variables. Whether you’re switching versions, troubleshooting, or simply removing unused software, it’s important to ensure that the process is thorough.

Remember, uninstalling Node.js is not always necessary unless you’re experiencing conflicts or issues. In many cases, using a version manager like nvm to switch between Node.js versions is a cleaner solution than full uninstallation.

YouTube Video:

How to Install and Uninstall Node.js (npm) on MacOS: Homebrew, Manual, and NVM Methods