Table of contents
1.
Introduction
2.
How to Uninstall Node.js in Ubuntu
2.1.
1. Using APT to Uninstall Node.js
2.2.
2. Using NVM to Uninstall Node.js
3.
Troubleshooting Common Issues
3.1.
1. Checking the System Path 
3.2.
2. Removing Residual Files 
4.
Best Practices for a Clean Uninstallation of Node.js
4.1.
Backup Important Data 
4.2.
Document Your Steps 
4.3.
Cleaning Up Post-Uninstallation
5.
How to Remove Global NPM Packages
5.1.
Cleaning the NPM Cache
5.2.
Checking Environment Variables
5.3.
Verifying the Uninstallation
6.
Frequently Asked Questions
6.1.
What should I do if Node.js is still running after uninstallation?
6.2.
Can I uninstall Node.js without affecting other packages on my system?
6.3.
Is it safe to manually remove Node.js files from my system?
6.4.
Is there a way to temporarily disable Node.js without uninstalling it?
7.
Conclusion
Last Updated: Jan 7, 2025
Easy

How to Uninstall Nodejs Ubuntu?

Author Sinki Kumari
0 upvote
Career growth poll
Do you think IIT Guwahati certified course can help you in your career?

Introduction

Node.js, a popular JavaScript runtime, is widely used for developing scalable network applications. Its non-blocking, event-driven architecture allows for efficient performance, making it a favorite among developers. However, there are times when you might need to uninstall Node.js from your Ubuntu system – maybe for an update, troubleshooting, or a clean slate. 

Uninstall Nodejs Ubuntu

This article guides you through the process of uninstalling Node.js on Ubuntu, ensuring a smooth & hassle-free removal. We'll cover methods, troubleshooting tips, & best practices to ensure you're equipped with all the necessary knowledge.

How to Uninstall Node.js in Ubuntu

When it comes to removing Node.js from an Ubuntu system, the process is straightforward, yet it requires careful attention to ensure no remnants are left behind. Node.js can be installed in various ways, and the uninstallation method depends on the initial installation method. Common methods include using a package manager like apt or nvm (Node Version Manager).

  1. Using APT to Uninstall Node.js
  2. Using NVM to Uninstall Node.js

1. Using APT to Uninstall Node.js

If you installed Node.js using the apt package manager, uninstallation involves a few simple commands. First, open your terminal and run:

sudo apt-get remove nodejs


This command removes Node.js but might leave behind some configuration files. To remove everything, including configuration files, use:

sudo apt-get purge nodejs


Lastly, to remove any unused packages and dependencies, execute:

sudo apt-get autoremove

2. Using NVM to Uninstall Node.js

If you've installed Node.js via NVM, it offers an easy way to remove any Node.js version. To uninstall a specific version, first, list all installed versions:

nvm ls


Then, to remove a specific version (e.g., v14.17.0), use:

nvm uninstall v14.17.0

Troubleshooting Common Issues

Even after uninstallation, sometimes you might encounter issues like Node.js still being accessible or version conflicts. This usually happens due to residual files or path references. 

Here's how to tackle these:

1. Checking the System Path 

Ensure that the system path doesn't include references to Node.js. You can check the path by running echo $PATH in your terminal.

2. Removing Residual Files 

Sometimes, Node.js files might remain in directories like /usr/local/bin or /usr/local/lib. Manually check these directories and remove any Node.js-related files.

Best Practices for a Clean Uninstallation of Node.js

To ensure a clean removal of Node.js from your Ubuntu system, follow these best practices:

Backup Important Data 

Before uninstallation, backup any important Node.js applications or configurations.

Document Your Steps 

Keep a record of the steps you take during uninstallation. This can be helpful for future reference or troubleshooting.

Cleaning Up Post-Uninstallation

After uninstalling Node.js, it's crucial to ensure that your system is completely free of any leftover files or configurations. This step is often overlooked, but it's essential for maintaining a clean and efficient system.

How to Remove Global NPM Packages

Even after uninstalling Node.js, global NPM packages might still reside on your system. To remove them, you can list all global packages using:

npm list -g --depth=0


Then, remove each package with:

npm uninstall -g [package-name]

Cleaning the NPM Cache

NPM stores a cache of downloaded packages, which can take up space. Clear it by running:

npm cache clean --force

Checking Environment Variables

Ensure that your .bashrc, .profile, or .bash_profile files in your home directory don't have any references to Node.js or NPM paths. If they do, remove those lines.

Verifying the Uninstallation

To confirm that Node.js is completely uninstalled, you can perform a few checks:

Run node -v and npm -v. If Node.js and NPM are uninstalled, these commands should not return a version number.

Check your directories (/usr/local/bin, /usr/local/lib, etc.) for any remaining Node.js files.

Frequently Asked Questions

What should I do if Node.js is still running after uninstallation?

Restart your computer. Sometimes, Node.js processes might linger in the memory, and a restart can resolve this issue.

Can I uninstall Node.js without affecting other packages on my system?

Uninstalling Node.js may not impact other packages unrelated to it; however, packages installed via npm will be affected. To keep these packages, you might consider reinstalling Node.js later or using a Node version manager.

Is it safe to manually remove Node.js files from my system?

Manually removing Node.js files is not recommended, as it can leave residual files and disrupt dependencies. It's safer to use official uninstall methods, which ensure a clean removal without leaving traces.

Is there a way to temporarily disable Node.js without uninstalling it?

Yes, you can temporarily disable Node.js by renaming its installation folder or updating system PATH variables to exclude Node.js. This allows easy reactivation by restoring the original folder name or PATH settings.

Conclusion

Uninstalling Node.js from Ubuntu is a straightforward process, but it requires attention to detail to ensure a complete and clean removal. Whether you're using APT or NVM, following the steps outlined in this guide will help you successfully uninstall Node.js and its associated elements. Remember to clean up residual files and check environment variables to avoid any lingering issues. With this knowledge, you're now equipped to manage Node.js installations on your Ubuntu system efficiently.

Live masterclass