Uninstall Node.JS Using Linux Command Line
To uninstall Node.js from your Linux system using the command line, you can follow these steps. The specific commands may vary depending on your Linux distribution, so I’ll provide instructions for a few common package managers: APT (Debian/Ubuntu), YUM (Red Hat/CentOS), and DNF (Fedora).
Check if Node is Already Installed or Not
Enter the following command to see if the node is installed or not
node -v
If an output displaying the version number of the node is shown then Node is installed in the system.
Steps to Uninstall Node Using Linux Package Managers
Step 1: Enter the following command to remove node
sudo apt remove nodejs
This will uninstall nodejs from the system
Step 2: Enter the following command to remove npm
sudo apt remove npm
This will uninstall npm from the system
Step 3: Enter the following command to remove any used files
sudo apt autoremove
Step 4: Enter the command to check if nodejs is present in the system or not
node -v
FAQ’s
What if I installed Node.js using a different package manager (e.g.nvm)?
If you install node from another package manager let say nvm(Node Version Manager) then you have use the commands of the nvm to uninstall nodejs from the system
Bellow is the command to remove nodejs using nvm
nvm uninstall node
What about global npm packages?
Global npm packages are the packages that available anywhere in the system and will be deleted after nodejs is uninstall. To keep the names of the global npm use the following command bellow
npm list -g --depth=0 > npm-global-packages.txtIt will store the global packages in a file then when you reinstall nodejs it will easier to reinstall the global packages
How do I uninstall Node.js if I installed it from the source code?
To uninstall from the source code, Navigate to that directory where you have installed and build the source code and use the following command
sudo make uninstall
How do I remove leftover configuration files after uninstalling Node.js?
To remove any leftover configuration files related to Node.js or npm, you can use the following command:
sudo apt-get purge nodejs npm
The purge option not only removes the package but also deletes the associated configuration files.
How do I uninstall Node.js on a distribution other than Ubuntu (e.g., CentOS, Fedora, or Debian)?
The specific package manager and commands may vary depending on the Linux distribution. For example, on CentOS and Fedora, you can use yum or dnf like this:
sudo yum remove nodejs npm
On Debian-based systems (e.g., Debian itself or Linux Mint), you can use apt-get like this:
sudo apt-get remove nodejs npm
Conclusion
Uninstalling Node.js on Linux involves using your package manager to remove the Node.js and npm packages. The exact command and method may vary depending on your Linux distribution and how Node.js was initially installed. Be cautious when uninstalling to ensure that you understand the implications for your system and any global npm packages you may have installed.