In this article, we will guide you through the process of completely removing Node.js and npm from your Ubuntu 18.04 system. This might be necessary if you want to reinstall them, switch to a different version, or if you no longer need them on your system.
To completely remove Node.js and npm from Ubuntu 18.04, you can use the apt-get command to uninstall them and then manually remove any remaining files and directories.
What are Node.js and npm?
How To Uninstall Node.js and npm
Uninstalling with apt-get
If you installed Node.js and npm using the
apt-get package manager, you can remove them by running the following commands in your terminal:
sudo apt-get remove nodejs sudo apt-get remove npm
sudo command is used to execute the following command with superuser privileges,
apt-get is the package handling utility in Ubuntu, and
remove is used to remove the package.
Manually Removing Remaining Files
In some cases, the above commands might not remove all the files related to Node.js and npm. To manually remove these remaining files and directories, you can use the following commands:
sudo rm -rf /usr/local/bin/npm /usr/local/share/man/man1/node* /usr/local/lib/dtrace/node.d ~/.npm ~/.node-gyp /opt/local/bin/node /opt/local/include/node /opt/local/lib/node_modules sudo rm -rf /usr/local/lib/node* sudo rm -rf /usr/local/include/node* sudo rm -rf /usr/local/bin/node*
rm is the remove command,
-rf is used to recursively remove directories and their contents without confirmation, and the paths are the locations of the Node.js and npm files and directories.
Note: Be very careful when using the
rm command, especially with the
-rf option, as it will permanently delete the specified files and directories. Make sure to double-check the paths before executing these commands.
Verifying the Removal
After executing the above commands, you can verify if Node.js and npm have been completely removed by running the following commands:
node -v npm -v
These commands will attempt to display the version numbers of Node.js and npm. If they have been successfully removed, these commands should return an error message.
If you still see the version numbers, it means that there are other installations of Node.js and npm on your system. You can run
which node and
which npm to check the paths of these remaining installations and remove them manually.
By following the steps outlined in this article, you should be able to completely remove Node.js and npm from your Ubuntu 18.04 system. If you encounter any issues or if you have any questions, feel free to leave a comment below.
Yes, you can reinstall Node.js and npm after removing them by following the installation instructions provided by the official Node.js website.
No, uninstalling Node.js and npm will not remove your Node.js applications. It will only remove the Node.js and npm runtime and package manager from your system. Your applications will remain intact unless you manually delete them.
You can check the installed versions of Node.js and npm by running the commands
node -v and
npm -v respectively in your terminal. These commands will display the version numbers of Node.js and npm if they are installed on your system.
If you have multiple versions of Node.js and npm installed, you can use the
nvm tools to manage different versions on your system. These tools allow you to switch between different versions of Node.js and npm easily.
rm -rf command can be dangerous if not used carefully. It permanently deletes the specified files and directories without confirmation. Make sure to double-check the paths before executing these commands to avoid accidentally deleting important files.