For Ubuntu 12.04:
sudo apt-get remove nodejs
This will uninstall nodejs as well as npm.
For Ubuntu 12.04:
sudo apt-get remove nodejs
This will uninstall nodejs as well as npm.
Edit: If you know which package manager was used to install, it is best to uninstall with the same package manager. Examples for apt, make, yum are in other answers.
This is a manual approach:
Running which node will return something like /path/bin/node.
Then run cd /path
This is all that is added by Node.JS.
rm -r bin/node bin/node-waf include/node lib/node lib/pkgconfig/nodejs.pc share/man/man1/node.1
Now the only thing I don't know about is npm and what it has installed. If you install npm again into a custom path that starts off empty, then you can see what it adds and then you will be able to make a list for npm similar to the above list I made for node.
Videos
How to uninstall Node, npm, and nvm?
How to uninstall Node.js in Windows Command Prompt?
How to uninstall npm in Windows?
As seen from the output of:
sudo apt-get purge nodejs
it is only removing node related packages i.e. relevant packages, nothing more.
On the other hand, when you do:
sudo apt-get purge --auto-remove nodejs
it is essentially doing:
sudo apt-get purge nodejs
sudo apt-get autoremove
and the removal of the gyp, linux-headers-4.4.0-18-generic etc packages are actually triggered by autoremove as they were installed as dependencies and no longer needed by any installed package, presumably because the main package has been removed.
So it is perfectly fine in this context to run:
sudo apt-get purge --auto-remove nodejs
If you are too paranoid, you can do it in two steps: first purge nodejs:
sudo apt-get purge nodejs
and then remove the orphan dependencies (till now, if any):
sudo apt-get autoremove
To remove node js, npm and node_modules from Ubuntu, you need to remove containers also which are at different locations in Ubuntu. These could be as:
/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
I have posted the procedure to remove NodeJS on my blog: AMCOS IT Support For Windows and Linux: To completely uninstall node js from Ubuntu.
First of all you need to run the following command from command terminal as sudo.
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_modulesRemove node or node_modules directories from /usr/local/lib with the help of following command.
sudo rm -rf /usr/local/lib/node*Remove node or node_modules directories from /usr/local/include with the help of following command.
sudo rm -rf /usr/local/include/node*Remove any node file or dir from /usr/local/bin with the help of following command.
sudo rm -rf /usr/local/bin/node*Go to home directory and remove any node or node_modules directory, if exists.
sudo apt-get remove nodejs
sudo apt-get remove npm
Then go to /etc/apt/sources.list.d and remove any node list if you have. Then do a
sudo apt-get update
Check for any .npm or .node folder in your home folder and delete those.
If you type
which node
you can see the location of the node. Try which nodejs and which npm too.
I would recommend installing node using Node Version Manager(NVM). That saved a lot of headache for me. You can install nodejs and npm without sudo using nvm.
It is better to remove NodeJS and its modules manually because installation leaves a lot of files, links and modules behind and later this creates problems when we reconfigure another version of NodeJS and its modules.
To remove the files, run the following commands:
sudo rm -rf /usr/local/bin/npm
sudo rm -rf /usr/local/share/man/man1/node*
sudo rm -rf /usr/local/lib/dtrace/node.d
rm -rf ~/.npm
rm -rf ~/.node-gyp
sudo rm -rf /opt/local/bin/node
sudo rm -rf /opt/local/include/node
sudo rm -rf /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*
I have posted a step by step guide with commands on my blog: AMCOS IT Support For Windows and Linux: To completely uninstall node js from Ubuntu.