Code360 powered by Coding Ninjas X Naukri.com. Code360 powered by Coding Ninjas X Naukri.com
Table of contents
1.
Introduction
2.
Uninstalling Node.js in Ubuntu
3.
Using APT to Uninstall Node.js
4.
Using NVM to Uninstall Node.js
5.
Troubleshooting Common Issues
5.1.
Checking the System Path 
5.2.
Removing Residual Files 
6.
Best Practices for a Clean Uninstallation
6.1.
Backup Important Data 
6.2.
Document Your Steps 
6.3.
Cleaning Up Post-Uninstallation
7.
Removing Global NPM Packages
7.1.
Cleaning the NPM Cache
7.2.
Checking Environment Variables
7.3.
Verifying the Uninstallation
8.
Frequently Asked Questions
8.1.
What should I do if Node.js is still running after uninstallation?
8.2.
How do I reinstall Node.js after uninstalling it?
8.3.
Is it necessary to uninstall global NPM packages separately?
9.
Conclusion
Last Updated: Mar 27, 2024
Easy

Uninstall Nodejs Ubuntu

Author Sinki Kumari
0 upvote
Create a resume that lands you SDE interviews at MAANG
Speaker
Anubhav Sinha
SDE-2 @
12 Jun, 2024 @ 01:30 PM

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. 

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.

Uninstalling 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).

Get the tech career you deserve, faster!
Connect with our expert counsellors to understand how to hack your way to success
User rating 4.7/5
1:1 doubt support
95% placement record
Akash Pal
Senior Software Engineer
326% Hike After Job Bootcamp
Himanshu Gusain
Programmer Analyst
32 LPA After Job Bootcamp
After Job
Bootcamp

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

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:

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.

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

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.

Removing 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.

How do I reinstall Node.js after uninstalling it?

You can reinstall Node.js by downloading the latest version from the official Node.js website or using a version manager like NVM.

Is it necessary to uninstall global NPM packages separately?

Yes, uninstalling Node.js doesn't automatically remove global NPM packages. They should be removed manually for a complete cleanup.

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.

You can refer to our guided paths on the Coding Ninjas. You can check our course to learn more about DSADBMSCompetitive ProgrammingPythonJavaJavaScript, etc. 

Also, check out some of the Guided Paths on topics such as Data Structure and AlgorithmsCompetitive ProgrammingOperating SystemsComputer Networks, DBMSSystem Design, etc., as well as some Contests, Test Series, and Interview Experiences curated by top Industry Experts.

Previous article
Traceroute Command in Linux
Next article
df Command in Linux
Live masterclass