technology

How to Uninstall Node.js on Different Operating Systems?

Node.js is an innovative and powerful tool for developers building diverse applications, from web servers to command-line interfaces. Its speed and versatility powered by the V8 JavaScript engine have cemented its popularity. However, there are moments when uninstalling Node.js becomes necessary, whether for an upgrade, troubleshooting, or shifting project requirements.

This guide provides comprehensive instructions for uninstalling Node.js across Windows, macOS, and Linux systems. By providing detailed, step-by-step instructions, we aim to make the process as smooth and error-free as possible for you. 

Why Uninstall Node.js?

There are several reasons why you might find yourself needing to uninstall Node.js from your computer. These reasons often revolve around the management and maintenance of your development environment. Here are the most common scenarios:

  • Version Upgrade: The most frequent cause for uninstalling Node.js is to upgrade to a newer version. Node.js is constantly evolving, with new features and performance improvements. Upgrading ensures access to these benefits, along with enhanced security patches.
  • Troubleshooting Issues: Sometimes, your Node.js installation might encounter issues due to corrupted files or conflicts with other software. Uninstalling and then reinstalling Node.js can often resolve these problems.
  • Switching Environments: Developers often switch between different environments or project requirements that necessitate different versions of Node.js. In such cases, removing the current version provides a clean slate for installing the specific version required.
  • System Cleanup: If you’re no longer working on Node.js projects or need to free up disk space, uninstalling Node.js helps tidy up your system, ensuring it runs efficiently.

Preparation Before Uninstallation

Before proceeding with the uninstallation of Node.js, it’s necessary to take a few preparatory steps to safeguard your development environment. Here’s what you need to do:

1. Backup Your Projects: 

Safeguarding your work is important. Make sure all your current projects are fully backed up. Use a cloud service, external drive, or another storage solution to store copies of your work. This step prevents any accidental loss of data during the uninstallation process.

2. List Global Packages: 

Node.js allows the installation of packages globally, making them accessible across projects. These global packages might be essential tools for your development workflow. To list all global packages you have installed, open a terminal or command prompt and run the command npm list -g –depth=0. This will display all globally installed packages at the top level, making it easier for you to note them down. Consider creating a document or a note with the list of these packages, as you may need to reinstall them after setting up Node.js again.

Uninstallation Methods (All Operating Systems):

Windows:

Uninstalling Node.js from a Windows system can be done through two main approaches: using the Control Panel or utilizing the Command Prompt for a more manual uninstallation. Here’s a guide to both methods:

1. Using the Control Panel

  • Open the Control Panel on your Windows system.
  • Click on “Programs and Features” or “Uninstall a program” under the Programs section. 
  • Scroll through the list until you find Node.js. Click on it to select it, then click the “Uninstall” button near the top of the window. Follow the on-screen prompts to complete the uninstallation process.
  • After uninstalling Node.js, it’s a good idea to check for any remaining folders or files that may not have been removed. Common directories to check include:
    • C:\Program Files\nodejs
    • C:\Users\[Your Username]\AppData\Roaming\npm (for npm packages)
    • C:\Users\[Your Username]\AppData\Roaming\npm-cache (for npm cache)
  • If these directories exist, delete them to ensure a clean uninstall.

2. Using Command Prompt (Alternative Method)

  • Press Win + R, type cmd, and press Enter to open the Command Prompt.
  • While the Command Prompt doesn’t directly offer an “uninstall” command for Node.js itself, you can start by removing the global packages you’ve installed. Type npm uninstall -g <package-name> for each global package you wish to remove.
  • After removing global packages, you must manually delete the Node.js installation and associated directories. Go Node.js installation folder (usually C:\Program Files\nodejs) and delete it. Additionally, remove the npm and npm-cache directories located in C:\Users\[Your Username]\AppData\Roaming\.
  • Finally, you might need to remove references to Node.js from your system’s environment variables. This can be done through the System Properties -> Environment Variables dialog, searching for and removing any variables related to Node.js (like NODE_PATH).

MacOS:

For macOS users, uninstalling Node.js can be performed through various methods, depending on how Node.js was initially installed. The process is straightforward if you use Homebrew, a popular package manager for macOS. Alternatively, if you installed Node.js directly from a package or in another manner, you might need to follow manual removal steps.

1. Uninstalling Node.js Installed via Homebrew

If you installed Node.js using Homebrew, you could uninstall it easily with the following command:

  • Launch the Terminal application from your Applications/Utilities folder or search for it using Spotlight.
  • In the Terminal, type the following command and press 

homwbrew command

  • This command tells Homebrew to remove Node.js from your system.

2. Manual Removal for Other Installation Methods

If you didn’t use Homebrew or need to ensure Node.js is completely removed, including all its files and directories, follow these steps:

  • Open Terminal and use the following commands to remove the main Node.js directories. These commands delete the Node.js binaries, modules, and cache from your system.
  • Remove Node.js binaries:

Binaries

  • Remove Node.js modules: cal/lib/node_modules

modules

  • You might also want to check for and remove any global npm packages or cache directories:

cache directories

  • Update your system’s $PATH if it includes references to Node.js or npm directories by editing your ~/.bash_profile, ~/.bashrc, ~/.zshrc, or other shell configuration files.
  • Verify Removal: After deleting these directories, you can verify that Node.js is uninstalled by typing node -v and npm -v in the Terminal. If uninstalled, these commands should return an error or indicate that Node.js and npm are not found.

Linux:

Uninstalling Node.js on Linux systems can be approached through the package manager provided by your Linux distribution or via manual removal if Node.js was installed from the source. Here’s how you can do both:

1. Uninstalling Node.js Using Package Manager

For Debian/Ubuntu:

  • Access the Terminal by searching for it in your applications menu or using a shortcut, typically Ctrl + Alt + T.
  • In the Terminal, type the following command and press Enter:

arduino uninstall

  • This command will prompt for your password and then proceed to remove Node.js from your system.
  • If you also want to remove npm and other related packages, you can use:

remove npm

  • And to clean up any unused packages:

unused packages

For RedHat/CentOS:

  • Open Terminal
  • Type the following command and hit Enter:

Pseudo yum

  • This will remove Node.js from your RedHat or CentOS system.
  • Consider running sudo yum autoremove to remove any packages that were installed with Node.js and are no longer needed.

2. Manual Removal for Node.js Installed from Source

If you installed Node.js by compiling it from source, you’ll need to manually remove the binaries, modules, and other files.

  • Remove Binaries: The main executable for Node.js is typically installed in /usr/local/bin. You can remove it by running:

Remove Binaries

  • Remove Libraries: Node.js libraries are located in /usr/local/lib. Use the following command to remove them:

Remove Libraries

  • Additional Directories: Depending on how Node.js was configured, you might also need to remove other directories, such as:

Additional Directories

  • Environment Cleanup: If you added Node.js to your PATH or set any environment variables related to Node.js, remember to remove those entries from files like ~/.bashrc, ~/.profile, or ~/.bash_profile.
  • Verification: After completing these steps, you can verify the removal by typing node -v and npm -v in the Terminal. If properly removed, these commands should not return a version number but report that Node.js and npm are not installed.

Troubleshooting Common Issues

During the uninstallation of Node.js, users might encounter several issues that can hinder the process. Addressing these common problems ensures a smoother experience. Here’s how to troubleshoot some of the frequent issues:

Node.js or npm Still Accessible After Uninstallation

  • Incomplete Uninstallation: If, after uninstallation, node -v or npm -v still returns version numbers, it likely means the uninstallation process was incomplete. Ensure all Node.js and npm files and directories have been removed, including manually deleting any leftover directories mentioned in previous steps.
  • Path Environment Variable: Check your system’s PATH environment variable. If it still contains references to Node.js or npm directories, remove these paths.
  • Restart Terminal or System: Sometimes, changes to the environment variables or system paths don’t take effect until you restart your Terminal or Command Prompt, or in some cases, your entire system.

Errors During Uninstallation

  • Permission Issues: If you encounter permission errors during uninstallation, especially on macOS and Linux, ensure you’re using sudo (for macOS and Linux) to grant administrative privileges to your commands. On Windows, run the Command Prompt as an Administrator.
  • Package Manager Problems: When using a package manager like apt-get, yum, or Homebrew, and you run into errors, try running sudo apt-get update or brew update to refresh your package manager’s database. This can resolve issues related to outdated information.

Unable to Reinstall Node.js

  • Corrupted Installation: If a previous installation was corrupted or incomplete, clear any caches related to your installation method. For npm, you can use npm cache clean –force. For Homebrew, try brew cleanup.
  • Conflicting Versions: Ensure that there are no conflicting versions of Node.js or npm. Use a version manager like nvm or nvm-windows to manage multiple versions more effectively.

General Tips

  • Documentation and Forums: The official Node.js website, Stack Overflow, and GitHub issues are excellent resources for troubleshooting specific errors. Often, someone else has encountered the same issue, and solutions or workarounds are available.
  • Clean System Reboot: Sometimes, a clean reboot of your system can resolve lingering issues by clearing out any processes that might be using Node.js or npm files.
  • Version Manager Use: Utilizing a version manager from the start can prevent many of these issues by isolating Node.js versions and dependencies from the system-wide environment, making installation, uninstallation, and version switching much more straightforward.

Conclusion


Uninstalling Node.js is often a necessary part of development, whether for troubleshooting, upgrades, or environment changes. While the process can seem daunting, this guide has aimed to provide actionable steps for smooth removal across operating systems.

The key is being prepared by backing up existing projects, noting global packages for later reinstallation, and understanding what directories require deletion. Each platform then has its quirks – utilizing Control Panel or Command Prompt on Windows, Homebrew or manual deletion on macOS, and package managers or source uninstalls on Linux.

With the proper commands and some diligence in following instructions, uninstalling Node.js can be straightforward. Common issues like permissions, outdated installers, or environment variable conflicts also have tractable solutions outlined here. Stepping through this process with care can save much frustration down the road.

Recent Blogs