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.

share|improve this question

15 Answers 15

up vote 1142 down vote accepted

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

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.

share|improve this answer
49  
Thanks for the detailed instruction, I add to additionally remove: /usr/local/bin/npm /usr/local/share/man/man1/node.1 /usr/local/lib/dtrace/node.d – ngeek Sep 13 '13 at 8:02
24  
I also had to rm -rf /Users/[homedir]/.npm. – brokenindexfinger Apr 18 '14 at 17:05
96  
I wish node had a built-in cleanup tool or something. – Chev Jul 29 '14 at 3:47
6  
I also ran brew doctor and then brew prune to clean up a bunch of broken symlinks for NPM. – Chris Jacob Sep 2 '14 at 11:54
32  
I threw together a script that I've now battle tested. Thanks @DominicTancredi this works great! gist.github.com/brock/5b1b70590e1171c4ab54 – brock Sep 13 '14 at 1:50

For brew users, OSX:

To remove:

brew uninstall node; 
# or `brew uninstall --force node` which removes all versions
brew prune;
rm -f /usr/local/bin/npm /usr/local/lib/dtrace/node.d;
rm -rf ~/.npm;

To install:

brew install node;
which node # => /usr/local/bin/node
export NODE_PATH='/usr/local/lib/node_modules' # <--- add this ~/.bashrc

You can run brew info node for more details regarding your node installs.


consider using NVM instead of brew

NVM (node version manager) is a portable solution for managing multiple versions of node

https://github.com/creationix/nvm

> nvm uninstall v4.1.0
> nvm install v8.1.2
> nvm use v8.1.2
> nvm list
         v4.2.0
         v5.8.0
        v6.11.0
->       v8.1.2
         system
  • you can use this with AVN to automatically switch versions as you hop between different projects with different node dependencies.
share|improve this answer
1  
How to set env vars so that node and npm are available after such install? – Maxim V. Pavlov Sep 13 '15 at 9:55
2  
@MaximV.Pavlov, answer has been updated – lfender6445 Sep 14 '15 at 11:45
12  
You may need to run brew with the --force flag to make sure all versions of node are removed: $ brew uninstall --force node – magikMaker Oct 6 '15 at 8:42
    
brew isn't so great. nvm is amazing – Johny Pie Dec 28 '17 at 23:10

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

UPDATE: 23 SEP 2016


If you're afraid of running these commands...

Thanks to jguix for this quick tutorial.

First, create an intermediate file:

lsbom -f -l -s -pf /var/db/receipts/org.nodejs.node.pkg.bom >> ~/filelist.txt

Manually review your file (located in your Home folder)

 ~/filelist.txt

Then delete the files:

cat ~/filelist.txt | 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.*

For 10.10.5 and above

Thanks Lenar Hoyt

Gist Comment Source: gistcomment-1572198

Original Gist: TonyMtz/d75101d9bdf764c890ef

lsbom -f -l -s -pf /var/db/receipts/org.nodejs.node.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.*
share|improve this answer
11  
Whoa-- this is terrifying. At least the first "rm" isn't a "rm -rf", which, if there's a blank line on the outpur of sbom, would remove all of /usr/local. Before doing anything so heavyhanded, scrutinize the sbom output and where all these dirs came from and make sure you know exactly what you're removing. – Don Hatch Apr 24 '15 at 1:45
12  
I should add... if you've got a healthy self-preservation instinct, it should be extremely difficult for you to type or copy-paste that second command, which begins with "sudo rm -rf /", at all. One sneeze, or the cat jumps on your keyboard, and you've destroyed your filesystem. – Don Hatch Apr 24 '15 at 6:14
    
Now you've added s second place too ;) – Michael Durrant Apr 25 '15 at 20:23
39  
Okay, I will not run this command around a cat – cosbor11 Jun 17 '15 at 23:31
1  
It’s org.nodejs.node.pkg.bom instead of org.nodejs.pkg.bom. – Lenar Hoyt Oct 10 '15 at 18:48

On Mavericks I install it from the node pkg (from nodejs site) and I uninstall it so I can re-install using brew. I only run 4 commands in the terminal:

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

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

share|improve this answer
22  
1 worked, but 2 fails. I get "no such keg: usr/local/Cellar/node" – PositiveGuy Feb 12 '15 at 3:32
    
Yep, this is the best if you have are running Mavericks – Dicer Feb 21 '17 at 16:18
  1. 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.*
    
  2. 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*
    
  3. go to /usr/local/include and delete any node and node_modules directory

    cd /usr/local/include
    
    sudo rm -rf node*
    
  4. if you installed with brew install node, then run brew uninstall node in your terminal

    brew uninstall node
    
  5. 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
    
  6. 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

share|improve this answer
5  
Removing node* is not a particularly safe way to proceed. There may be other binaries with that prefix. – Lenar Hoyt Oct 10 '15 at 19:28
1  
Great, finally after 3 days, when every now and then there were npm issues, removed completely and reinstall using brew on my mac, works like a charm. – Amit Bravo Aug 10 '16 at 11:56

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
share|improve this answer

I'm not sure if it's because I had an old version (4.4.5), or if it's because I used the official installer, but most of the files referenced in other answers didn't exist on my system. I only had to remove the following:

~/.node-gyp
~/.node_repl_history
/usr/local/bin/node
/usr/local/bin/npm
/usr/local/include/node
/usr/local/lib/dtrace/node.d
/usr/local/lib/node_modules
/usr/local/share/doc/node
/usr/local/share/man/man1/node.1
/usr/local/share/systemtap/tapset/node.stp

I decided to keep ~/.npm because I was planning on reinstalling Node with Homebrew.

share|improve this answer
    
This answer was made in 2012, so I'm sure it has some legacy-ness to it. Now, if new answers show up, I upvote them after reviewing if they're effective. – Dominic Tancredi Feb 4 '17 at 18:27

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

share|improve this answer
1  
This is exactly what happened to me :-) thx for your addendum answer. Well, I started having several versions of Cordova, and one npm could not remove the one Cordova and vice versa. – peter_the_oak Feb 28 '15 at 12:41

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.

share|improve this answer
1  
I was about to post this, and see that the author himself posted the best possible answer to the problem: use node-reinstall once and you'll never look back. Got me hitting the ground running and ready for more development! Cheers for this @brockangelo! – Wallace Sidhrée Oct 18 '15 at 9:51
2  
Warning..... the node-reinstall script contains this line: sudo rm -rf $HOME/{local,lib,include,node*,npm,.npm*} So if you happen to independently have a directory of that name in your $HOME (as I do), it's going to get clobbered! – terrycojones May 26 '16 at 23:47

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

rm -rf /usr/local/share/man/man1/npm*
share|improve this answer
    
This should be a comment on the appropriate answer, not a new answer. – Edward Anderson Nov 21 '17 at 1:40

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
share|improve this answer
    
How to run it parallel? say i want to run 2 versions? – YumYumYum Nov 10 '16 at 22:50

You can clone https://github.com/brock/node-reinstall and run the simple command as given in the repository.After that just restart your system.
This is the simplest method and also worked for me.

share|improve this answer

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
share|improve this answer

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.

share|improve this answer
4  
Link-only answers are discouraged on Stack Overflow. – Andrew Grimm Jun 22 '16 at 7:55

(server: ubuntu 14)

1.) install nvm (node version manager) https://github.com/creationix/nvm

2.) nvm install node

3.) npm -v (inquire npm version => 3.8.6)

4.) node -v (inquire node version => v6.0.0)

share|improve this answer
    
This is a thread about mac. Why throw ubuntu into the mxi? – billy_comic Jan 4 '17 at 15:11

protected by Community Jun 9 '16 at 4:23

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged or ask your own question.