1433

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.

Kamil Kiełczewski
  • 53,729
  • 20
  • 259
  • 241
Dominic Tancredi
  • 36,322
  • 7
  • 31
  • 49
  • 2
    https://github.com/nodejs/node/issues/7371#issuecomment-341530174 and https://gist.github.com/dotcomputercraft/b7283bd52f4b5389e748 and http://stackabuse.com/how-to-uninstall-node-js-from-mac-osx/ – Pacerier Nov 02 '17 at 19:53
  • /usr/bin/node is another one... – Aaron Blenkush Jan 19 '18 at 00:15
  • 1
    this might help for whoever installed node via pkg file. https://superuser.com/questions/36567/how-do-i-uninstall-any-apple-pkg-package-file – karthikeayan Jul 02 '18 at 14:32
  • Mac 10.13.5 has got /Users/myusername/node_modules should I delete this folder as well ? I searched in this thread but nobody faced this issue it seems – vikramvi Oct 29 '18 at 06:02
  • @Pacerier even after following instruction in gist, still node and npm exists on Mac OS 10.13.5 – vikramvi Jul 22 '19 at 10:47
  • @vikramvi, what folders in all? – Pacerier Dec 23 '20 at 12:47

29 Answers29

1795

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 

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

You may also need to do:

sudo rm -rf /opt/local/bin/node /opt/local/include/node /opt/local/lib/node_modules
sudo rm -rf /usr/local/bin/npm /usr/local/share/man/man1/node.1 /usr/local/lib/dtrace/node.d

Additionally, NVM modifies the PATH variable in $HOME/.bashrc, which must be reverted manually.

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.

Dave Jarvis
  • 28,853
  • 37
  • 164
  • 291
Dominic Tancredi
  • 36,322
  • 7
  • 31
  • 49
  • Worked for me, too. Thank you! Had to run the node installer though. `n` and `nvm` both did not work for me on first try. – SimplGy Apr 15 '13 at 21:23
  • I'm attempting to follow these steps but Terminal spits out "permission denied" and tells me the directory is not empty. Any ideas? – lukeseager Jul 03 '13 at 14:29
  • 93
    I also had to `rm -rf /Users/[homedir]/.npm`. – Lou Groshek Apr 18 '14 at 17:05
  • 19
    Also needed to remove `/Users/[homedir]/.nvm` – n0pe Jul 22 '14 at 23:23
  • Include folders are where `c` headers are stored. – Kites Sep 01 '14 at 20:37
  • 45
    I also ran `brew doctor` and then `brew prune` to clean up a bunch of broken symlinks for NPM. – Chris Jacob Sep 02 '14 at 11:54
  • 55
    I threw together a script that I've now battle tested. Thanks @DominicTancredi this works great! https://gist.github.com/brock/5b1b70590e1171c4ab54 – brock Sep 13 '14 at 01:50
  • 16
    I also had to add: `sudo rm -rf ~/.node-gyp`. I had added it with MacPorts before I switched to brew. – JESii Nov 15 '14 at 15:22
  • 3
    Probably want to run `brew uninstall --force node` to make sure that it removes *all* versions of Node in Homebrew. – iono Feb 24 '15 at 06:20
  • I was dumb enough to install node packages as sudo, so I also had to `sudo rm -rf /root/.npm`. – approxiblue May 21 '15 at 19:42
  • Thank you for this post! I also had some additional permission issues and had to run `sudo chown -R \`whoami\` /usr/local` to get brew to install node. – Anil Natha May 25 '15 at 19:54
  • 1
    On Ubuntu, the paths do not include `\local`. – Dan Nissenbaum Jun 27 '15 at 21:08
  • Also remove `sudo rm -rf ~/.node` and `sudo rm -rf ~/.node-gyp` – Nitin Bansal Aug 21 '15 at 12:43
  • Also check if which node is - /Users/xyz/var/bin/node Then delete from here also. – A J Sep 23 '15 at 09:27
  • 7
    Additionally remove: `/usr/local/share/systemtap/tapset/node.stp` – Luke Schoen Jan 04 '16 at 12:40
  • 1
    The two commands don't seem to delete `/usr/local/include/node/`, but the summary underneath it mentions that folder. Am I misunderstanding this answer? – Andrew Grimm Jun 22 '16 at 23:18
  • The two commands in your answer are not equivalent. The second one deletes `~/.npm ~/.node-gyp /opt/local/bin/node opt/local/include/node /opt/local/lib/node_modules`, the first does not. – Big McLargeHuge Jan 25 '17 at 15:40
  • Another file should be removed: ```/usr/bin/node``` – Ke Yang Jun 14 '17 at 02:36
  • There are also man pages in section 7 `/usr/local/share/man/man7/npm-*` – Drew Stephens Aug 14 '17 at 17:46
  • Also had to remove node from /usr/lib, /usr/include, and /usr/bin – Chad Aug 23 '17 at 19:14
  • 4
    Mac user. Another two commands which help me clear `sudo rm -rf /usr/local/share/doc/node` `sudo rm -rf /usr/local/n/versions/node` – JParkinson1991 Sep 12 '17 at 09:02
  • 1
    How does: `sudo rm -rf /usr/local/bin/npm /usr/local/share/man/man1/node* /usr/local/lib/dtrace/node.d ~/.npm ~/.node-gyp` delete `/usr/local/lib/node_modules` or `/usr/local/lib/node`? I don't see any of those folders specified in the command. (In manual deletion steps that claims to be the same as the command) – Jonathan002 Mar 05 '18 at 13:34
  • don't install node+npm on your OS directly, use a docker container https://hub.docker.com/_/node/ , this will make your life incredibly simpler when it comes to cleanup – Pierluigi Vernetto Jun 04 '18 at 16:19
  • For me I kept seeing my old version of npm after running all of the above commands. I had to restart my computer in order for npm to show the updated version. I'm on Ubuntu 64 bit. – Michael Jul 04 '18 at 13:08
  • Any time @Mehr. The community here has been extraordinary in supporting this question and answer. – Dominic Tancredi Aug 20 '18 at 04:47
  • 1
    Also needed to remove /Users/[homedir]/.npmrc – Yaniv Oct 19 '18 at 14:10
  • Mac 10.13.5 has got /Users/myusername/node_modules should I delete this folder as well ? – vikramvi Oct 29 '18 at 05:59
  • 1
    does this system still not have a way of uninstalling things? I mean, what century are they stuck in?? – bytepusher Dec 31 '18 at 22:19
  • This thread demonstrates to me that NodeJs is not a professional tool; at least, not on the Mac. – Bane Jan 11 '19 at 21:28
  • Everyone should be careful when upgrading npm. There is a trap. Check https://docs.npmjs.com/try-the-latest-stable-version-of-np before proceed or will end up cleaning it all again. – MiguelSlv Mar 16 '19 at 19:57
  • /usr/local/bin/node as well – Darko Maksimovic Jun 28 '19 at 17:29
  • I had to remove: `/Volumes/node_modules`, `~/.npm`, and `~/.nvm` and had no node or npm binaries in `/usr/local/bin`. `~/.nvm` was referenced in `~/.bash_profile`. I ran `rm -Rf /Volumes/node_modules`, check. But `rm -Rf ~/.npm` failed with and without `sudo`, so from Terminal I did `open ~/.npm`, hit cmd-shift-. (Mojave - Finder shows dot-prefixed files), and used the UI instead (which worked!). Then `rm -Rf ~/.nvm` got “access denied”, but `sudo rm -Rf ~/.nvm` worked! Removed nvm from `~/.bash_profile`. I hope this helps someone... because this didn't follow ANY of the doco I could find. – jrypkahauer Jun 30 '19 at 02:45
  • 1
    I also had to delete /usr/local/share/doc/node/gdbinit – Krishna Shetty Aug 02 '19 at 13:08
  • 1
    removed in addition.. ~./npmrc ~/.npm-global ~/.npm. /usr/local/include/node – user1769790 Aug 05 '20 at 03:51
  • 1
    Just a tip that I found helpful after following this: if you (after completing all the steps above) run `brew install node`, brew will complain about any previously-existing node files/dirs and will refuse to install node, failing with an error. You can then look at that error and see which existing file(s) you need to get rid of. – hotmeatballsoup Mar 09 '21 at 18:07
  • Thank you, what a headache I had over this! – mohammad hosein abedini Mar 30 '21 at 09:33
583

For brew users, OSX:

To remove:

brew uninstall node; 
# or `brew uninstall --force node` which removes all versions
brew cleanup;
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/nvm-sh/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.

lfender6445
  • 25,940
  • 9
  • 95
  • 82
  • 3
    How to set env vars so that node and npm are available after such install? – Maxim V. Pavlov Sep 13 '15 at 09:55
  • 13
    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 06 '15 at 08:42
  • `-bash: /usr/local/bin/npm: No such file or directory` what can I do now? – ValRob May 07 '18 at 18:03
  • try `which npm`, its possible it got installed somewhere else? if it did get installed somewhere else, youll need to make sure the folder is in your $PATH – lfender6445 May 07 '18 at 18:52
  • I am wondering why you are using semicolons at the end of your bash commands in the terminal. – Kallaste Jun 01 '18 at 22:11
  • i've had trouble in the past copying to clipboard and having line breaks removed on paste. this just ensures the commands are captured as as separate ideas regardless, but they aren't by any means necessary. – lfender6445 Jun 02 '18 at 00:01
  • Mac 10.13.5 has got /Users/myusername/node_modules should I delete this folder as well ? I searched in this thread but nobody faced this issue it seems – vikramvi Oct 29 '18 at 06:06
  • yes, you can usually safely remove`~/node_modules` or any node_modules folder for that matter. it will be created or re-generated (if you need it) when you run `npm install` – lfender6445 Oct 29 '18 at 17:41
  • when I try to uninstall using brew and --force I get `Error: Could not remove /usr/local/Cellar/node/11.1.0! Check its permissions` what next? – alex Mar 09 '19 at 18:08
  • hi alex - this sounds like a separate issue. have you seen https://stackoverflow.com/questions/16432071/how-to-fix-homebrew-permissions – lfender6445 Mar 09 '19 at 21:22
  • ```nvm install 11.13.0``` and ```nvm use 11.13.0``` – Ashok R Apr 11 '19 at 10:36
  • 7
    > "consider using NVM instead of brew"; Ironically you can install NVM **with** brew!; Great tip, thanks. – HankCa May 08 '19 at 03:39
  • 2
    Using NVM helped. – coderpc Jul 03 '19 at 17:16
  • As recommendation nowadays try use ASDF instead of NVM – Bruno de Oliveira Jun 01 '20 at 20:11
  • Finally found a solution with nvm deactivate nvm uninstall – Alwaysalearner Feb 24 '21 at 03:41
  • After ```running brew uninstall --force node``` && ```brew cleanup```, ```node --version``` and ```npm version``` are still returning a version – Skillz May 01 '21 at 16:57
  • you can use `which node` to determine the location of these binaries, perhaps you installed them with different tooling – lfender6445 May 03 '21 at 18:33
195

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.*
DaveyJake
  • 2,143
  • 1
  • 14
  • 18
  • 18
    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 01:45
  • 19
    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 06:14
  • Now you've added s second place too ;) – Michael Durrant Apr 25 '15 at 20:23
  • I apologize if my approach is rather "aggressive" in some respects, however, I guess I'm rather comfortable and know my way around Terminal? It's always important to scrutinize every command you send for one typo can--LITERALLY--cost everything. The only reason why I shared these commands was mostly because I hoped people would just copy & paste instead of (what feels like) talk down on it. – DaveyJake Aug 05 '15 at 01:53
  • 2
    It’s `org.nodejs.node.pkg.bom` instead of `org.nodejs.pkg.bom`. – Lenar Hoyt Oct 10 '15 at 18:48
  • This still works in 2017 for uninstalling Node.js v7.7. – newguy Jun 13 '17 at 08:44
  • 1
    @DonHatch copy the line without the first letter so it starts with `udo..` and then prepend `s` before running it. – youurayy Oct 05 '17 at 23:28
  • 2
    The lsbom command outputs relative paths so the script was trying to delete paths that looked like `/usr/local/./node/yada`. To remove the `./` prefix I used cut filter: `lsbom -f -l -s -pf /var/db/receipts/org.nodejs.node.pkg.bom | cut -c 3- | while read f; do sudo rm /usr/local/${f}; done` – timiscoding Jan 18 '20 at 04:29
150

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 cleanup --prune-prefix

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

Muzammil
  • 1,431
  • 1
  • 15
  • 23
Pedro Polonia
  • 2,262
  • 2
  • 19
  • 29
44

I have summarized the existing answers and made sure Node.js is COMPLETELY ERASED along with NPM.

Lines to copy to terminal:

brew uninstall node;
which node;
sudo rm -rf /usr/local/bin/node;
sudo rm -rf /usr/local/lib/node_modules/npm/;
brew doctor;
brew cleanup --prune-prefix;
Flávio Faria
  • 6,370
  • 3
  • 37
  • 57
Pengguna
  • 3,249
  • 1
  • 19
  • 26
  • I followed these steps and it seems to have worked. I still have directories in my root folder like `.node-gyp/`, `.npm/`, `.npm-global/`, and `.nvm/`. Can I delete these or should I keep them if I plan on reinstalling node? – WaterTrash Mar 30 '20 at 17:25
37
  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

Manos Nikolaidis
  • 18,967
  • 11
  • 60
  • 72
Johel Alvarez
  • 655
  • 10
  • 8
  • 9
    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
  • 3
    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
  • 1
    When fired first command getting `can't open /var/db/receipts/org.nodejs.pkg.bom: No such file or directory **** Can't open /var/db/receipts/org.nodejs.pkg.bom.` Please help – Ahtesham Shah Jun 20 '19 at 05:09
  • 1
    Even after doing these steps on Mac 10.13.5, still I could see npm and node what may be going wrong ? – vikramvi Jul 22 '19 at 10:54
29

https://stackabuse.com/how-to-uninstall-node-js-from-mac-osx/

Run following commands to remove node completely from system in MACOS

sudo rm -rf ~/.npm ~/.nvm ~/node_modules ~/.node-gyp ~/.npmrc ~/.node_repl_history
sudo rm -rf /usr/local/bin/npm /usr/local/bin/node-debug /usr/local/bin/node /usr/local/bin/node-gyp
sudo rm -rf /usr/local/share/man/man1/node* /usr/local/share/man/man1/npm*
sudo rm -rf /usr/local/include/node /usr/local/include/node_modules
sudo rm -rf /usr/local/lib/node /usr/local/lib/node_modules /usr/local/lib/dtrace/node.d
sudo rm -rf /opt/local/include/node /opt/local/bin/node /opt/local/lib/node
sudo rm -rf /usr/local/share/doc/node
sudo rm -rf /usr/local/share/systemtap/tapset/node.stp

brew uninstall node
brew doctor
brew cleanup --prune-prefix



After this i will suggest to use following command to install node using nvm

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bash

from https://github.com/nvm-sh/nvm

Akshay Vijay Jain
  • 6,159
  • 4
  • 31
  • 34
27

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
Anja Ishmukhametova
  • 1,308
  • 14
  • 14
25

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.

Big McLargeHuge
  • 11,456
  • 8
  • 64
  • 92
  • 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 04 '17 at 18:27
10

Worked for me.

$node --version

v11.1.0

$nvm deactivate

$nvm uninstall v11.1.0
Mohammad Usman
  • 30,882
  • 16
  • 80
  • 78
Inês Gomes
  • 2,201
  • 1
  • 16
  • 26
10
  • Delete node and/or node_modules from /usr/local/lib

          ex code:
          cd /usr/local/lib
          sudo rm -rf node
          sudo rm -rf node_modules
    
  • Delete node and/or node_modules from /usr/local/include

  • Delete node, node-debug, and node-gyp from /usr/local/bin
  • Delete .npmrc from your home directory (these are your npm settings, don't delete this if you plan on re-installing Node right away)
  • Delete .npm from your home directory
  • Delete .node-gyp from your home directory
  • Delete .node_repl_history from your home directory
  • Delete node* from /usr/local/share/man/man1/
  • Delete npm* from /usr/local/share/man/man1/
  • Delete node.d from /usr/local/lib/dtrace/
  • Delete node from /usr/local/opt/local/bin/
  • Delete node from /usr/local/opt/local/include/
  • Delete node_modules from /usr/local/opt/local/lib/
  • Delete node from /usr/local/share/doc/
  • Delete node.stp from /usr/local/share/systemtap/tapset/
Rajiv Singh
  • 654
  • 7
  • 13
8

After

brew uninstall node

I had to know which node

which node

then remove that

rm -rf /usr/local/bin/node
Hos Mercury
  • 1,256
  • 2
  • 14
  • 22
8

If you have already installed nvm then execute the following commands

  • nvm deactivate - This will remove /.nvm/*/bin from $PATH
  • nvm list - To list out all the versions of node installed in the system
  • nvm uninstall <version> in you can specify all the versions you want to uninstall.

It is always a good that you install node using nvm and uninstall using nvm rather than brew .

This solution worked for me.

Additional Commands

  • which node to know the path of node installed in your system. You can rm this directory to uninstall node manually. Then you may need to adjust the PATH file accordingly.
Akhil Nadh PC
  • 502
  • 1
  • 6
  • 21
7

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.

Community
  • 1
  • 1
brock
  • 2,152
  • 5
  • 26
  • 28
  • 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 09:51
  • 3
    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
6

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

rm -rf /usr/local/share/man/man1/npm*
Giacomo1968
  • 23,903
  • 10
  • 59
  • 92
5

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

Ragunath Jawahar
  • 18,666
  • 20
  • 102
  • 154
toutpt
  • 4,915
  • 3
  • 33
  • 44
  • 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
5

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
swipe
  • 91
  • 1
  • 4
4

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.

mary_jane
  • 1,782
  • 3
  • 18
  • 37
4

The best way is to download an installer package: .pkg on mac. Prefer the latest stable version.

Here is the link: Node.js

This package will eventually overwrite the previous version and set environment variables accordingly. Just run the installer and its done within a few clicks.

vkrishna17
  • 797
  • 8
  • 17
4

Complete uninstall Nodejs on macOS Big Sur version 11.2.3 (20D91)


Introduction

First thing first,

I want to say thank you for sharing this trick @tonymtz.

My system is running macOS Big Sur version 11.2.3 (20D91) with nodejs Latest Current Version: 15.14.0 (includes npm 7.7.6) installed from the official website.

I tried to fully uninstall nodejs on my MacBook Pro in order to re-install it with homebrew package manager using:

lsbom -f -l -s -pf /var/db/receipts/org.nodejs.pkg.bom | while read f; do  sudo rm /usr/local/${f}; done

but I was facing an issue like @AhteshamShah mentioned in @JohelAlvarez's answer:

When fired first command getting: can't open /var/db/receipts/org.nodejs.pkg.bom: No such file or directory **** Can't open /var/db/receipts/org.nodejs.pkg.bom. Please help – Ahtesham Shah Jun 20 '19 at 5:09

I dived into the original post linked by @JohelAlvarez, reading all the comments and I've found this comment from @e2tha-e:

@tonymtz On my installation of Node v4.0.0 on Yosemite 10.10.5, the first line needed to be lsbom -f -l -s -pf /var/db/receipts/org.nodejs.node.pkg.bom | while read f; do sudo rm /usr/local/${f}; done A different filename from org.nodejs.pkg.bom Otherwise, this worked like a charm!

@e2tha-e was right, on macOS Big Sur version 11.2.3 (20D91) with nodejs Latest Current Version: 15.14.0 (includes npm 7.7.6) installed from official website, the file name is not org.nodejs.pkg.bom but org.nodejs.node.pkg.bom .

You can check this when you cd /var/db/receipts/ && ls -la.

Solution for installation from Nodejs's official website

With your preferred Terminal, fully uninstall Nodejs from your system like this :

Option 1
  1. lsbom -f -l -s -pf /var/db/receipts/org.nodejs.node.pkg.bom | while read f; do sudo rm /usr/local/${f}; done
  2. sudo rm -rf /usr/local/lib/node /usr/local/lib/node_modules /var/db/receipts/org.nodejs.*
Option 2

Go to /var/db/receipts/ and delete any org.nodejs.*

  1. cd /var/db/receipts/ && ls -la
  2. sudo rm -rf org.nodejs.*

Go to /usr/local/lib and delete any node and node_modules

  1. cd /usr/local/lib && ls -la
  2. sudo rm -rf node*

Go to /usr/local/include and delete any node and node_modules directory

  1. cd /usr/local/include && ls -la
  2. sudo rm -rf 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

  1. cd /usr/local/bin && ls -la
  2. sudo rm -rf /usr/local/bin/npm
  3. sudo rm -rf /usr/local/bin/node

You may need to do this too:

  1. sudo rm -rf /usr/local/share/man/man1/node.1
  2. sudo rm -rf /usr/local/lib/dtrace/node.d
  3. sudo rm -rf ~/.npm

After that, you can check if there is still node in your system with which node or find all occurrences for node in your system.


Tips

  1. Search where node files are with find / -name 'node' | sed -E 's|/[^/]+$||' |sort -u
  2. Before running shared code by others, check your directories before to make sure you write the right file name.

3

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
3

As a companion to the answers explaining cleanup and install via homebrew, I found that homebrew itself provided clear indications of the symlink clashes.

Unfortunately it provides these one by one as it encounters them, so it is a little laborious, but it does seem to find all the clashes and was the only way I could get a clean install with homebrew.

Essentially, the process is:

  1. use homebrew to uninstall node
  2. clean homebrew
  3. use homebrew to install node and note any flagged clashing file
  4. delete the flag clashing file (or whole directory if it is a 'node' directory)
  5. goto step 1 until you get a clean install

Diagrammatically:

Here is a screen output from the last steps of my install - you can see it results in a clean install (eventually...):

computer1:DevResources user1$ brew install node
Updating Homebrew...
==> Downloading https://homebrew.bintray.com/bottles/node-13.1.0.mojave.bottle.tar.gz
Already downloaded: /Users/user1/Library/Caches/Homebrew/downloads/da904f1fdab6f6b2243a810b685e67b29a642c6e945f086e0022323a37fe85f9--node-13.1.0.mojave.bottle.tar.gz
==> Pouring node-13.1.0.mojave.bottle.tar.gz
Error: The `brew link` step did not complete successfully
The formula built, but is not symlinked into /usr/local
Could not symlink share/systemtap/tapset/node.stp
Target /usr/local/share/systemtap/tapset/node.stp
already exists. You may want to remove it:
  rm '/usr/local/share/systemtap/tapset/node.stp'

To force the link and overwrite all conflicting files:
  brew link --overwrite node

To list all files that would be deleted:
  brew link --overwrite --dry-run node

Possible conflicting files are:
/usr/local/share/systemtap/tapset/node.stp
/usr/local/lib/dtrace/node.d
==> Caveats
Bash completion has been installed to:
  /usr/local/etc/bash_completion.d
==> Summary
  /usr/local/Cellar/node/13.1.0: 4,591 files, 54.2MB
computer1:DevResources user1$ rm '/usr/local/share/systemtap/tapset/node.stp'
computer1:DevResources user1$ brew uninstall node
Uninstalling /usr/local/Cellar/node/13.1.0... (4,591 files, 54.2MB)
computer1:DevResources user1$ brew cleanup
computer1:DevResources user1$ brew install node
Updating Homebrew...
==> Downloading https://homebrew.bintray.com/bottles/node-13.1.0.mojave.bottle.tar.gz
Already downloaded: /Users/user1/Library/Caches/Homebrew/downloads/da904f1fdab6f6b2243a810b685e67b29a642c6e945f086e0022323a37fe85f9--node-13.1.0.mojave.bottle.tar.gz
==> Pouring node-13.1.0.mojave.bottle.tar.gz
Error: The `brew link` step did not complete successfully
The formula built, but is not symlinked into /usr/local
Could not symlink lib/dtrace/node.d
Target /usr/local/lib/dtrace/node.d
already exists. You may want to remove it:
  rm '/usr/local/lib/dtrace/node.d'

To force the link and overwrite all conflicting files:
  brew link --overwrite node

To list all files that would be deleted:
  brew link --overwrite --dry-run node

Possible conflicting files are:
/usr/local/lib/dtrace/node.d
==> Caveats
Bash completion has been installed to:
  /usr/local/etc/bash_completion.d
==> Summary
  /usr/local/Cellar/node/13.1.0: 4,591 files, 54.2MB
computer1:DevResources user1$ rm '/usr/local/lib/dtrace/node.d'
computer1:DevResources user1$ 
computer1:DevResources user1$ brew uninstall node
Uninstalling /usr/local/Cellar/node/13.1.0... (4,591 files, 54.2MB)
computer1:DevResources user1$ brew cleanup
computer1:DevResources user1$ brew install node
Updating Homebrew...
==> Downloading https://homebrew.bintray.com/bottles/node-13.1.0.mojave.bottle.tar.gz
Already downloaded: /Users/user1/Library/Caches/Homebrew/downloads/da904f1fdab6f6b2243a810b685e67b29a642c6e945f086e0022323a37fe85f9--node-13.1.0.mojave.bottle.tar.gz
==> Pouring node-13.1.0.mojave.bottle.tar.gz
==> Caveats
Bash completion has been installed to:
  /usr/local/etc/bash_completion.d
==> Summary
  /usr/local/Cellar/node/13.1.0: 4,591 files, 54.2MB
computer1:DevResources user1$ node -v
v13.1.0
Mick
  • 19,483
  • 1
  • 40
  • 91
2

First of all, you need to deactivate node: (mac) after install new node version.

nvm deactivate

This is removed /Users/user_name/.nvm/*/bin from $PATH

And after that node was updated

node --version
v10.9.0
AlexSh
  • 933
  • 11
  • 11
2

In my case none of the other answers worked because I previously downgraded to node8. So instead of doing above, following worked for me:

which node

which returned /usr/local/bin/node@8 instead of /usr/local/bin/node

so i executed this command:

brew uninstall node@8

which worked and then downloaded latest pkg from official site and installed. After that I had to close my terminal and start again to access new version

Raza Ahmed
  • 2,461
  • 1
  • 29
  • 43
2

Docker - alternative approach

Docker is some-kind of super-fast virtual machine which can be use to run tools like node (instead install them directly on mac-os). Advantages to do it are following

  • all stuff ('milions' node files) are install inside docker image/container (they encapsulated in few inner-docker files)

  • you can map your mac directory with project to your docker container and have access to node - but outside docker, mac-os sytem don't even know that node is installed. So you get some kind of 'virtual' console with available node commands which can works on real files

  • you can easily kill node by find it by docker ps and kill by docker rm -f name_or_num

  • you can easily uninstall docker image/containers by one command docker rmi ... and get free space - and install it again by run script (below)

  • your node is encapsulated inside docker and don't have access to whole system - only to folders you map to it

  • you can run node services and easily map they port to mac port and have access to it from web browser

  • you can run many node versions at the same time

  • in similar way you can install other tools like (in many versions in same time): php, databases, redis etc. - inside docker without any interaction with mac-os (which not notice such software at all). E.g. you can run at the same time 3 mysql db with different versions and 3 php application with different php version ... - so you can have many tools but clean system

  • TEAM WORK: such enviroment can be easily cloned into other machines (and even to windows/linux systems - with some modifications) and provide identical docker-level environment - so you can easily set up and reuse you scripts/dockerfiles, and setup environment for new team member in very fast way (he just need to install docker and create similar folder-structure and get copy of scripts - thats all). I work this way for 2 year and with my team - and we are very happy

Instruction

  • Install docker using e.g. this instructions

  • Prepare 'special' directory for work e.g. my directory is /Users/kamil/work (I will use this directory further - but it can be arbitrary) - this directory will be 'interface' between docker containers and your mac file ststem. Inside this dir create following dir structure:

    /Users/kamil/work/code - here you put your projects with code

    /Users/kamil/work/tools

    /Users/kamil/work/tools/docker-data - here we map containers output data like logs (or database files if someone ouse db etc.)

    /Users/kamil/work/tools/docker

    /Users/kamil/work/tools/docker/node-cmd - here we put docker node scripts

  • inside tools create file .env which will contain in one place global-paths used in other scripts

    toolspath="/Users/kamil/work/tools"
    codepath="/Users/kamil/work/code"
    workpath=/Users/kamil/work
  • innside dir ../node-cmd create file dockerfile with following content

    # default  /var/www/html (mapped to .../code folder with projects)
    FROM node
    
    WORKDIR /work
    
    # Additional arbitrary tools (ng, gulp, bower)
    RUN npm install -g n @angular/cli bower gulp grunt
    
    CMD while true; do sleep 10000; done
    
    # below ports are arbitrary
    EXPOSE 3002 3003 3004 4200
  • innside dir ../node-cmd create file run-container with following content (this file should be executable e.g. by chmod +x run-container) - (notice how we map port-s and directories form external 'world' to internal docker filesystem)

    set -e
    cd -- "$(dirname "$0")" # this script dir (not set on doubleclick)
    source ../../.env
    toolsdir=$toolspath/docker-data
    workdir=$workpath
    
    if [ ! "$(docker ps | grep node-cmd)" ] 
    then 
      docker build -t node-cmd .
      docker rm -f node-cmd |:
      docker run -d --name node-cmd -p 4200:4200 -p 4201:4201 -p 3002:3002 -p 3003:3003 -p 3004:3004 -v $toolsdir/node-cmd/logs:/root/.npm/_logs -v $workdir:/work node-cmd
    fi
  • ok now you can add some project e.g. work/code/myProject and add to it following file 'run-cmd' (must be executable)

    cd -- "$(dirname "$0")"
    ../../tools/docker/node-cmd/run-container
    docker exec -it node-cmd bash -c "cd /work/code/myProject; bash"
  • then if you run above script (by double-click), you will see console with available node commands in project directory e.g. npm install

  • to run project in background (e.g some serwice) e.g. run web-server angular-cli application you can use following script (named run-front -must be executable) - (you must also edit /etc/hosts file to add proper domain)

    cd -- "$(dirname "$0")"
    open "http://my-angular.local:3002"
    ../../tools/docker/node-cmd/run-container
    docker exec -it node-cmd  /bin/sh -c "cd /work/code/my-angular-project; npm start"
    cat         # for block script and wait for user ctrl+C
Community
  • 1
  • 1
Kamil Kiełczewski
  • 53,729
  • 20
  • 259
  • 241
1

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.

Here is the relevant part for convenience:

Solution

This solution fixes the error caused by trying to run npm update npm -g. Once you're finished, you also won't need to use sudo to install npm modules globally.

Before you start, make a note of any globally installed npm packages. These instructions will have you remove all of those packages. After you're finished you'll need to re-install them.

Run the following commands to remove all existing global npm modules, uninstall node & npm, re-install node with the correct defaults, configure the location for global npm modules to be installed, and then install npm as its own pacakge.

rm -rf /usr/local/lib/node_modules
brew uninstall node
brew install node --without-npm
echo prefix=~/.npm-packages >> ~/.npmrc
curl -L https://www.npmjs.com/install.sh | sh

Node and npm should be correctly installed at this point. The final step is to add ~/.npm-packages/bin to your PATH so npm and global npm packages are usable. To do this, add the following line to your ~/.bash_profile:

export PATH="$HOME/.npm-packages/bin:$PATH"

Now you can re-install any global npm packages you need without any problems.

pcatre
  • 640
  • 10
  • 19
  • 4
    Link-only answers are discouraged on Stack Overflow. – Andrew Grimm Jun 22 '16 at 07:55
  • @AndrewGrimm makes sense, I copied the relevant part. – pcatre Mar 20 '18 at 19:53
  • 1
    After putting the following command I am getting the following error: curl -L https://www.npmjs.com/install.sh | sh ....npm ERR! A complete log of this run can be found in: npm ERR! /Users/bddev/.npm/_logs/2018-10-18T20_02_34_337Z-debug.log npm ERR! code E404 npm ERR! 404 Not Found: 1.535s@latest npm ERR! A complete log of this run can be found in: npm ERR! /Users/bddev/.npm/_logs/2018-10-18T20_02_36_399Z-debug.log It failed – Shoaib Ahmed Oct 18 '18 at 20:03
1

If you're unable to locate node just run whereis node and whereis npm and whereis nvm and you can remove the listed directories as needed.

You'll also need to entirely close your terminal and reopen it for changes to take effect.

andromeda
  • 2,944
  • 3
  • 20
  • 33
0

@lfender6445 answer worked just fine for me to uninstall

Now to reinstall, I had problems installing the last version instead of the most stable one, so to install a specific node version you should do:

brew install node@10 // 10 is the version I want
brew link node@10
Lucas Andrade
  • 2,353
  • 2
  • 19
  • 38
-8

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

aze
  • 9