How do I completely uninstall Node.js, and reinstall from beginning (Mac OS X)

My version of node is always v0.6.1-pre even after I install brew node and NVM install v0.6.19.

My node version is:

node -v
v0.6.1-pre

NVM says this (after I install a version of node for the first time in one bash terminal):

nvm ls
v0.6.19
current:    v0.6.19

But when I restart bash, this is what I see:

nvm ls
v0.6.19
current:    v0.6.1-pre
default -> 0.6.19 (-> v0.6.19)

So where is this phantom node 0.6.1-pre version and how can I get rid of it? I'm trying to install libraries via NPM so that I can work on a project.

I tried using BREW to update before NVM, using "brew update" and "brew install node". I've tried deleting the "node" directory in my /usr/local/include and the "node" and "node_modules" in my "/usr/local/lib". I've tried uninstalling npm and reinstalling it following these instructions.

All of this because I was trying to update an older version of node to install the "zipstream" library. Now there's folders in my users directory, and the node version STILL isn't up to date, even though NVM says it's using 0.6.19.

Ideally, I'd like to uninstall nodejs, npm, and nvm, and just reinstall the entire thing from scratch on my system.

Apparently, there was a /Users/myusername/local folder that contained a include with node and lib with node and node_modules. How and why this was created instead of in my /usr/local folder, I do not know.

Deleting these local references fixed the phantom v0.6.1-pre. If anyone has an explanation, I'll choose that as the correct answer.

EDIT:

You may need to do the additional instructions as well:

sudo rm -rf /usr/local/{lib/node{,/.npm,_modules},bin,share/man}/{npm*,node*,man1/node*}

which is the equivalent of (same as above)..

sudo rm /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

or (same as above) broken down..

To completely uninstall node + npm is to do the following:

  1. go to /usr/local/lib and delete any node and node_modules
  2. go to /usr/local/include and delete any node and node_modules directory
  3. if you installed with brew install node, then run brew uninstall node in your terminal
  4. check your Home directory for any local or lib or include folders, and delete any node or node_modules from there
  5. go to /usr/local/bin and delete any node executable

Then download nvm and follow the instructions to install node. The latest versions of node come with npm, I believe, but you can also reinstall that as well.

I know this post is a little dated but just wanted to share the commands that worked for me in Terminal when removing Node.js

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.*

In mavericks i install from the node pkg (from nodejs site) and I uninstall it so I can re-install using brew. I only do 3 commands at terminal:

  1. sudo rm -rf /usr/local/lib/node_modules/npm/
  2. brew uninstall node
  3. brew doctor

If there is still a node installation, repeat step 2. Then all is ok, I install using brew install node

Cheers,

Pedro

For brew users, OSX:

brew uninstall node;
brew prune;
rm -f /usr/local/bin/npm;
rm -f /usr/local/lib/dtrace/node.d;
rm -rf ~/.npm;

then

brew install node;
which node #=> /usr/local/bin/node

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

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

Source: tonyMtz

I have been hit by an issue during uninstall of Node.js on my mac. I had some strange behavior like npm is still their even after having removing it with all this.

It was because I had an old install done with macport. So you also have to uninstall it using port:

sudo port uninstall nodejs

It may have install many different versions of Node.js so uninstall them all (one by one).

downgrade node to 0.10.36

  sudo npm cache clean -f
  sudo npm install -g n
  sudo n 0.10.36

upgrade node to stable v

  sudo npm cache clean -f
  sudo npm install -g n
  sudo n stable

I'm not sure about the Mac OS installer, but I've found that the NodeJS .msi installer for Windows has an option to uninstall Node. I did that and it worked perfectly.

One thing that isn't pointed out in the other answers, since this is for Mac specifically is that you want to use the pkgutil command to forget the packages. In my case the commands were

sudo pkgutil --forget org.nodejs.node.npm.pkg
sudo pkgutil --forget org.nodejs.pkg

Additionally you can use the --files flags to list the files associated with the package to make sure you got everything.

Additional to the main answer I needed to remove all npm instances found in:

rm -rf /usr/local/share/man/man1/npm*

Expanding on Dominic Tancredi's awesome answer, I've rolled this into a bash package and stand-alone script. If you are already using the "Back Package Manager" called bpkg you can install the script by running:

$ bpkg install -g brock/node-reinstall

Or you can have a look at the script on Github at brock/node-reinstall. The script allows you to re-install node using nvm or nave, and to specify a node version as your default.

maybe you need to make

hash -r 

it helps with problem of symlink

$ node -v
$ bash: /opt/local/bin/node: No such file or directory

This fixed it for me Fixing npm On Mac OS X for Homebrew Users. And it does not require too many steps.

Just go to the solution part if you don't care about the why.

I had installed Node.js from source downloaded from the git repository. I installed with:

./configure
$ make
$ sudo make install

Because the make file supports it, I can do:

$ sudo make uninstall