Uninstall Node.JS using Linux command line? - linux

How do you uninstall node.js using the cmd line in linux?

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.

If you installed from source, you can issue the following command:
sudo make uninstall
If you followed the instructions on https://github.com/nodejs/node/wiki to install to your $HOME/local/node, then you have to type the following before the line above:
./configure --prefix=$HOME/local/node

Sorry the answer of George Bailey does work very fine when you
want absolutely remove the node from your machine.
This answer is referred from : #tedeh
https://github.com/nodesource/distributions/issues/486
If you wanna install a new version of node you have to use the code below
sudo rm -rf /var/cache/yum
sudo yum remove -y nodejs
sudo rm /etc/yum.repos.d/nodesource*
sudo yum clean all
And add new nodejs version to "yum" an new version of node
#using this command for Node version 8
curl --silent --location https://rpm.nodesource.com/setup_8.x | sudo bash -
#using this command for Node version 10
curl --silent --location https://rpm.nodesource.com/setup_10.x | sudo bash -
Install nodejs
sudo yum -y install nodejs
I hope it gonna help you guy!!!

To uninstall node I followed the accepted answer by #George, as I no longer have the sources, but before doing so I ran:
sudo npm rm npm -g
That seemed to get rid of npm from the system directories such as /usr/bin/npm and /usr/lib/npm. I got the command from here. I then found a ~/.npm directory, which I deleted manually. Honestly I don't know if every trace of npm has been removed, but I can't find anything else.

If you installed node using curl + yum:
sudo curl --silent --location https://rpm.nodesource.com/setup_4.x | bash -
sudo yum -y install nodejs
Then you can remove it using yum:
sudo yum remove nodejs
Note that using the curl script causes the wrong version of node to be installed. There is a bug that causes node v6.7 to be installed instead of v4.x intended by the path (../setup_4.x) used in the curl script.

This is better to remove NodeJS and its modules manually because installation leaves a lot of files, links and modules behind and later it create problems while we reconfigure another version of NodeJS and its modules.
Run 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*
and this done.
A step by step guide with commands is at http://amcositsupport.blogspot.in/2016/07/to-completely-uninstall-node-js-from.html
This helped me resolve my problem.

I think Manoj Gupta had the best answer from what I'm seeing. However, the remove command doesn't get rid of any configuration folders or files that may be leftover. Use:
sudo apt-get purge --auto-remove nodejs
The purge command should remove the package and then clean up any configuration files. (see this question for more info on the difference between purge and remove). The auto-remove flag will do the same for packages that were installed by NodeJS.
See the accepted answer on this question for a better explanation.
Although don't forget to handle NPM! Josh's answer covers that.

The answer of George Bailey works fine.
I would just add the following flags and use sudo if needed:
sudo rm -rf bin/node bin/node-waf include/node lib/node lib/pkgconfig/nodejs.pc share/man/man1/node

if you want to just update node, there's a neat updater too
https://github.com/creationix/nvm
to use,
git clone git://github.com/creationix/nvm.git ~/.nvm
source ~/.nvm/nvm.sh
nvm install v0.4.1

I think this works, at least partially (have not investigated):
nvm uninstall <VERSION_TO_UNINSTALL>
eg:
nvm uninstall 4.4.5

If you have yum you could do:
yum remove nodesource-release* nodejs
yum clean all
And after that check if its deleted:
rpm -qa 'node|npm'

after installing using the "ROCK-SOLID NODE.JS PLATFORM ON UBUNTU" script, i get this output. Which tells you how to uninstall nodejs.
Done. The new package has been installed and saved to
/tmp/node-install/node-v0.8.19/nodejs_0.8.19-1_i386.deb
You can remove it from your system anytime using:
dpkg -r nodejs

Best way to go around this is to do it right from the BEGINNING:
INSTALL BREW
#HERE IS HOW: PASTE IN TERMINAL
sudo apt-get install build-essential curl git m4 ruby texinfo libbz2-dev libcurl4-openssl-dev libexpat-dev libncurses-dev zlib1g-dev
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/linuxbrew/go/install)"
Then at the end of your .bashrc file(In your home directory press Ctrl + H)
export PATH="$HOME/.linuxbrew/bin:$PATH"
export MANPATH="$HOME/.linuxbrew/share/man:$MANPATH"
export INFOPATH="$HOME/.linuxbrew/share/info:$INFOPATH"
Then restart terminal so the modification to .bashrc are reloaded
TO INSTALL NODE
brew install node
TO CHECK VERSION
node -v
npm -v
TO UPDATE NODE
brew update
brew upgrade node
TO UNINSTALL NODE
brew uninstall node

To Remove nodejs installed in centos 8:
From your home directory, run the below command
sudo yum remove nodejs
Enter y to confirm your command

In addition to apt or yum removal, clean any residual files to avoid conflicts if you ever install a new version:
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
sudo rm -rf ~/.npm
sudo 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*

For Centos 7 and 8
Remove NodeJS
sudo yum remove -y nodejs
sudo rm -rf /var/cache/yum
sudo rm /etc/yum.repos.d/nodesource*
sudo yum clean all
Remove residual files
whereis node
sudo rm -rfv /usr/bin/node /usr/local/bin/node /usr/share/man/man1/node.1.gz
sudo rm -rfv /usr/bin/npm /usr/local/bin/npm /usr/share/man/man1/npm.1.gz
sudo rm -rfv /usr/local/bin/npx
sudo rm -rfv /usr/local/lib/node*
sudo rm -rfv /usr/local/include/node*
sudo rm -rfv /usr/lib/node_modules/

Just remove these files. No need to do anything else.
rm -rf ~/.nvm
rm -rf ~/.npm
rm -rf ~/.bower

Related

npm update broke npm

I just followed this guide to update npm (as my nodered camera module wasn't working) and ran
npm install -g npm
but now my npm install seems completely broken. If I just type
npm
or
npm update
I get
/usr/local/lib/node_modules/npm/bin/npm-cli.js:79
let notifier = require('update-notifier')({pkg})
^^^
SyntaxError: Block-scoped declarations (let, const, function, class)
not yet supported outside strict mode
I've tried
sudo apt-get remove npm
sudo apt-get install npm
but the reinstall didn't help.
I think my node version needs upgrading from v4.8.2 but I thought that was only possible with npm?
You probably have npm installed twice, one is in /usr/local/bin and the other in /usr/bin.
First, you can try to remove the npm module that has been installed by upgrading npm. Try to run this:
rm -r /usr/local/lib/node_modules/npm
/usr/bin/npm uninstall npm
Once you have a running version of npm, install a more recent version of node before upgrading npm. Then, remove the version of your linux distribution.
If the first solution doesn't work, another approach is to install a recent version of node (without using npm of course):
curl -sL https://deb.nodesource.com/setup_14.x | sudo -E bash -
sudo apt-get install -y nodejs
(solution for centos....I assume it would work also on ubuntu):
to clean up completely my centos machine, I have additionally done the following - my user is "centos" and my home is /home/centos:
sudo rm -rf /usr/local/bin/npm
sudo rm -rf /usr/local/bin/npx
sudo rm -rf /usr/lib/node_modules/
sudo rm -rf /usr/bin/npm
sudo rm -r /usr/local/lib/node_modules/
sudo rm -rf /usr/local/bin/node
sudo rm -rf /usr/bin/npm
sudo rm -rf /usr/lib/node_modules/
rm -rf /home/centos/.npm/
rm -rf /home/centos/node*
rm -rf /home/centos/.node-gyp/
sudo rm -rf /root/.npm/
sudo rm /usr/bin/node
sudo rm -rf /usr/local/include/node
only at this point I reinstalled again:
wget http://nodejs.org/dist/latest/node-v11.4.0-linux-x64.tar.gz
sudo tar --strip-components 1 -xzvf node-v* -C /usr/local
and things are working again:
node --version
v11.4.0
npm --version
6.4.1
To those who used google to find this, you may be tempted to install via
curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash - and then installing with sudo apt install nodejs.
However, I somehow ran into this issue regardless. Please keep in mind that npm#6 dropped support for node#<=4, and that is a contributing factor here. If you want to be sure that everything is installed at the latest, correct versions, I very highly recommend installing through nvm.
Via the nvm instructions on their GitHub: You can add the install script with
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.34.0/install.sh | bash
Then you can start using nvm. You will likely have to restart your terminal, so after installation, exit the terminal, start it up again, and check that nvm is installed with nvm --version.
If everything goes well, you can install any specific version of node with npm in tow. The latest stable version of node as of writing this is 10.15.3, so
nvm install 10.15.3
And of course, if you need help, nvm --help has a list of options.
If you are using nvm to install npm and node, try this solution.
Get to know where exactly is the currently used node and npm is installed:
which node
In my case, it was /home/ubuntu/.nvm/versions/node/
Now, delete all the versions of node using:
sudo rm -rf /home/ubuntu/.nvm/versions/node/
You can now use nvm to install your required version of node and npm.
nvm install 4.9.1
Other answers didn't work for me on Ubuntu and ended up in a dead end, with a broken npm or unable to reinstall/update npm.
The radical solution I used :
1/ Remove all traces of node. Follow this page, using the remove.sh script at the bottom :
http://kselax.ru/en/npm-errors/
2/ Then reinstall from scratch nodejs + npm using the latest install script :
https://github.com/nodesource/distributions/blob/master/README.md
For me, reinstalling npm worked:
npm install -g npm

Nodejs is there after uninstalling it in macOS

I am trying to uninstall nodejs in mac but after uninstalling it, Nodejs is still there. I have tried brew uninstall node and brew uninstall node --force it is uninstalling one version of node but my old version of nodejs is still there.
I Runned
node -v
it is showing
v4.8.4
after the uninstall process
Quoting from this GitHub SOURCE. It worked for me.
Run these steps
# first:
lsbom -f -l -s -pf /var/db/receipts/org.nodejs.pkg.bom | while read f; do sudo rm /usr/local/${f}; done
sudo rm -rf /usr/local/lib/node /usr/local/lib/node_modules /var/db/receipts/org.nodejs.*
# To recap, the best way (I've found) to completely uninstall node + npm is to do the following:
# go to /usr/local/lib and delete any node and node_modules
cd /usr/local/lib
sudo rm -rf node*
# go to /usr/local/include and delete any node and node_modules directory
cd /usr/local/include
sudo rm -rf node*
# if you installed with brew install node, then run brew uninstall node in your terminal
brew uninstall node
# check your Home directory for any "local" or "lib" or "include" folders, and delete any "node" or "node_modules" from there
# go to /usr/local/bin and delete any node executable
cd /usr/local/bin
sudo rm -rf /usr/local/bin/npm
sudo rm -rf /usr/local/bin/node
ls -las
# you may need to do the additional instructions as well:
sudo rm -rf /usr/local/share/man/man1/node.1
sudo rm -rf /usr/local/lib/dtrace/node.d
sudo rm -rf ~/.npm

How to remove docker aufs folder?

I've uninstalled docker with the following command
sudo apt-get purge docker-engine
sudo apt-get autoremove --purge docker-engine
The above command works fine, no problem. But when I try to run sudo rm -rf /var/lib/docker as instructed in Docker docs, I get the following error
rm: cannot remove '/var/lib/docker/aufs/mnt/04fc3de09910bf8fae3d0430b0debbf3032d480bef4ced9f40b1f532bf478ef9': Is a directory
What should I do to remove this content?
First remove docker-engine using sudo apt remove docker-engine
Reboot.
Then remove /var/lib/docker/aufs with sudo rm -rf /var/lib/docker/aufs.
Perform the Ubuntu upgrade with sudo do-release-upgrade
You can now re-install docker-engine using sudo apt install docker-engine (or don't, your choice)
Try sudo su and then rm -rf /var/lib/docker/aufs/mnt/04fc3de09910bf8fae3d0430b0debbf3032d480bef4ced9f40b1f532bf478ef9

npm Cannot find module 'minimatch'

I update my Node.js to 5.5.0.
But it does not work when i use npm.
It reports error:
Cannot find module 'minimatch'.
But Node.js version 4.2 is ok on my mac.
Remove this folder /usr/local/lib/node_modules/npm/node_modules/rimraf/node_modules
rm -rf /usr/local/lib/node_modules/npm/node_modules/rimraf/node_modules
This happened to me when I updated my node through the binary but also had a previous version installed through homebrew .
The way I resolved this was, uninstalling node and npm completely and reinstalling using the binary found on their website .
sudo rm /usr/local/bin/npm
sudo rm /usr/local/share/man/man1/node.1
sudo rm /usr/local/lib/dtrace/node.d
sudo rm -rf ~/.npm
sudo rm -rf ~/.node-gyp
sudo rm /opt/local/bin/node
sudo rm /opt/local/include/node
sudo rm -rf /opt/local/lib/node_modules
brew unlink nodejs
and reinstall .
I ran into probably the same exact problem as you.
I went from 4.2.3 LTS to 5.9, and all npm functionality ceased, always generating that error.
I had to do the following:
Uninstall Node
Save anything in your node installation folder that you may want to keep
Completely delete the node installation
Re-install 5.9
Everything was tip-top after that. I purged the folder after I noticed that there was the old 4.2.3 installer in the Installer directory. I didn't know what the ramifications of that were, but better safe than sorry.

Uninstall nodejs installed from binary distribution files

I have installed nodejs(node-v4.2.1) in ubuntu 14.04 using zip file(tar.gz) downloaded from node js website(not using apt-get install.The location of installed node is /usr/local/bin.
while trying to uninstall it using sudo apt-get purge,sudo apt-get remove &sudo apt-get autoremove is not working.How could I uninstall it?
I got the solution from the links given below
http://hungred.com/how-to/completely-removing-nodejs-npm/
How to install node binary distribution files on Linux
I did the following steps and it works fine
sudo rm -rf /usr/local/bin/npm
sudo rm -rf /usr/local/bin/node
sudo rm -rf /usr/local/lib/node_modules/
sudo rm -rf /usr/local/include/node/
sudo rm -rf /usr/local/share/man/man1/node.1
cd /home/userName
ls -ld .?* (to display hidden files)
# delete files/folders related with node
sudo rm -f .node_repl_history
sudo rm -rf .npm
To Re-install new version follow the below steps
1.Download new version from Node official website.In my case my downloaded file is node-v6.9.4-linux-x64.tar.xz
2.Move the file into /usr/local directory using the command
sudo mv Downloads/node-v6.9.4-linux-x64.tar.xz /usr/local
3.Use the below command to extract into appropriate directories in /usr/local
sudo tar --strip-components 1 -xf node-v6.9.4-linux-x64.tar.xz
-xf is to unzip .tar.xz for tar.gz use -xzf
4.verify installation
node --version
Check if there is an uninstall script in the zip, otherwise you need to clean /usr/local manually for any node related artefacts.

Resources