Node.js is a popular runtime environment that allows you to run JavaScript on the server-side. While it’s an essential tool for many developers, there may come a time when you need to uninstall it from your Ubuntu system. Whether you’re upgrading to a new version, troubleshooting issues, or simply cleaning up your system, this guide will walk you through the steps to completely uninstall Node.js, NPM (Node Package Manager), and Node from your Ubuntu machine.
Step 1: Check the Installed Version
Before you start the uninstallation process, it’s a good idea to check the currently installed versions of Node.js and NPM. You can do this by opening your terminal and running the following commands:
To check the Node.js version:
$ node -v
To check the NPM version:
$ npm -v
This step helps you verify which versions you have installed so you can ensure they are removed correctly.
Step 2: Uninstall Node.js and NPM
To uninstall Node.js and NPM from your Ubuntu system, you can use the package manager apt
. Here are the commands to remove them:
- Remove Node.js:
sudo apt-get remove nodejs
- Remove NPM:
sudo apt-get remove npm
- Additionally, you may want to remove any residual configuration files for Node.js and NPM:
sudo apt-get purge nodejs npm
Step 3: Verify Uninstallation
After running the uninstallation commands, it’s a good practice to verify that Node.js and NPM have been successfully removed. To check this, run the following commands:
$ node -v npm -v
If the commands return an error or indicate that the program is not installed, it means Node.js and NPM have been successfully uninstalled from your system.
Step 4: Remove Node.js and NPM Global Packages
Uninstalling Node.js and NPM from your system does not remove global Node packages you may have installed. To remove these global packages, you can use the npm list -g --depth=0
command to list them, and then use npm uninstall -g
to uninstall them one by one.
For example, to list your global packages:
$ npm list -g --depth=0
To uninstall a global package (replace package_name
with the actual package name):
$ npm uninstall -g package_name
Repeat the uninstallation process for each global package you want to remove.
Step 5: Remove Node.js and NPM Files and Directories
After uninstalling Node.js and NPM, there may still be residual files and directories left on your system. To remove them, use the following commands:
- Delete the
/usr/local/bin/node
binary:sudo rm -rf /usr/local/bin/node
- Remove any related files in the
/usr/local/lib
directory:sudo rm -rf /usr/local/lib/node*
- Delete the
/usr/local/bin/npm
binary:sudo rm -rf /usr/local/bin/npm
- Remove any related files in the
/usr/local/lib
directory:sudo rm -rf /usr/local/lib/npm*
Step 6: Clear the Cache
Node.js and NPM may leave behind cached files that you can remove. To do this, use the following command:
$ sudo npm cache clean -f
Conclusion
Uninstalling Node.js, NPM, and Node from your Ubuntu system can be necessary for various reasons, and it’s crucial to do it correctly to avoid any issues. By following these steps, you should be able to completely remove Node.js and NPM from your machine, including any residual files and global packages. This ensures a clean uninstallation, allowing you to install or upgrade Node.js with a fresh start when needed.
Found this article interesting? Follow Brightwhiz on Facebook, Twitter, and YouTube to read and watch more content we post.