How to Uninstall Node JS in Ubuntu?

Uninstalling Node.js from your Ubuntu system is a straightforward process. Whether you're following a Node.js tutorial, completing a web development course, or considering pay after placement courses, the removal of Node.js involves a few simple steps.

Here's a step-by-step guide on how to uninstall Node.js from Ubuntu:

1. Using Package Manager:

Open your terminal, which you can do by pressing Ctrl + Alt + T.

bashCopy codesudo apt-get remove nodejs
sudo apt-get remove npm

These commands will uninstall Node.js and npm (Node Package Manager) from your system.

2. Removing Residual Configuration Files:

While the above commands remove the Node.js package, there might be residual configuration files that you'd want to delete.

bashCopy codesudo apt-get purge nodejs
sudo apt-get purge npm

The purge command not only removes the packages but also their configuration files.

3. Verify Uninstallation:

To ensure that Node.js and npm are uninstalled, you can check their versions. If they are still installed, you'll see version numbers; otherwise, you'll get a command not found message.

bashCopy codenode -v
npm -v

4. Remove Node.js Distributions Installed via NVM:

If you installed Node.js using Node Version Manager (NVM), you should also uninstall it using the following commands:

bashCopy codenvm deactivate
nvm uninstall --lts

Replace --lts with the specific version you have installed if needed.

5. Remove NVM Itself:

If you used NVM for Node.js installation, you can remove NVM as well.

bashCopy coderm -rf ~/.nvm

6. Additional Cleanup:

To clean up any remaining files or directories related to Node.js, you can run:

bashCopy codesudo rm -rf /usr/local/bin/node
sudo rm -rf /usr/local/bin/npm
sudo rm -rf /usr/local/lib/node_modules
sudo rm -rf /etc/npmrc

7. Verify Again:

Finally, verify that Node.js and npm are no longer present on your system.

bashCopy codenode -v
npm -v

This series of commands ensures a thorough uninstallation of Node.js from your Ubuntu system. Whether you're following a node.js tutorial, enrolled in a web development course, or considering pay after placement courses, a clean uninstallation is crucial if you plan to switch or reinstall Node.js in the future.