admin管理员组

文章数量:1125551

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.

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 edited May 14, 2020 at 10:49 Kamil Kiełczewski 92.1k34 gold badges394 silver badges370 bronze badges asked Jun 24, 2012 at 13:40 Dominic TancrediDominic Tancredi 42.3k7 gold badges35 silver badges50 bronze badges 7
  • 3 github.com/nodejs/node/issues/7371#issuecomment-341530174 and gist.github.com/dotcomputercraft/b7283bd52f4b5389e748 and stackabuse.com/how-to-uninstall-node-js-from-mac-osx – Pacerier Commented Nov 2, 2017 at 19:53
  • /usr/bin/node is another one... – Aaron Blenkush Commented Jan 19, 2018 at 0:15
  • 2 this might help for whoever installed node via pkg file. superuser.com/questions/36567/… – karthikeayan Commented Jul 2, 2018 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 Commented Oct 29, 2018 at 6:02
  • @Pacerier even after following instruction in gist, still node and npm exists on Mac OS 10.13.5 – vikramvi Commented Jul 22, 2019 at 10:47
 |  Show 2 more comments

34 Answers 34

Reset to default 1 2 Next 2028

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.

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.

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 (check https://github.com/nvm-sh/nvm for latest version)

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

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


Why nvm?
this is a good question, there will be projects requiring different versions of node,
i.e. A requires node version 12 while B requires node version 14. This version management of node is provided by nvm only.

UPDATE: 23 SEP 2016 - Intel Macs 10.11.x and above

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

Intel Macs 10.10.x and below

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

ORIGINAL: 7 JUL 2014

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

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

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;

Complete uninstall Node.js on macOS Monterey version 12.0.1

To check the current node version installed on your system:

# node -v
# v14.15.0

Enter the given below commands to delete Node from your system:

# cd /usr/local/include
# sudo rm -R node
# cd ../lib
# sudo rm -R node_modules
# cd ../bin
# sudo rm -R node

to check that node doesn't exist anymore

# node -v
# -bash: node: command not found

Install Node.js on macOS Monterey version 12.0.1

  1. Download the LTS version of node from the official website
  1. Double click on the node-v16.13.1.pkg installation package and continue with the default settings

  2. Type node -v in your terminal to print the current installed version of node : v16.13.1 & npm -v to print the current npm version installed on your machine : 8.1.2

  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

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

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


Introduction

First things 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. – 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.

Steps to Uninstall NodeJS:

For MacOS Monterey with M1 chip, please follow the link below to uninstall node completely from the system. I have tried multiple ways but this one worked finally.

Uninstall NodeJS & NPM from Mac M1 Monterey

Additionally, please execute the following commands at the end to remove node related directories from bin folder.

sudo rm -R node-sass
sudo rm -R npm
sudo rm -R npx

To verify that node is removed:

node --version

It should say command not found.

Steps to Install NodeJS:

Enable Rosseta terminal on your Mac with M1 chip. How to enable Rosseta terminal

Use nvm (Node Version Manager) to install NodeJS on your machine. Why nvm?? Because you can run multiple versions of NodeJS (you can work with a new app as well as a Legacy app).

How to install multiple versions of NodeJS using nvm

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

Create a .zshrc file if not exists.

touch ~/.zshrc

Install node using nvm.

nvm install node # "node" is an alias for the latest version
nvm install 14.7.0 # or 16.3.0, 12.22.1, etc

To verify the number of NodeJS versions available:

nvm ls

After

brew uninstall node

I had to know which node

which node

then remove that

rm -rf /usr/local/bin/node
  • 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/

Worked for me.

$node --version

v11.1.0

$nvm deactivate

$nvm uninstall v11.1.0

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.

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.

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.

I have been hit by an issue during uninstall of Node.js on my mac. I had some strange behavior like npm is still there even after having to remove 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 installed many different versions of Node.js so uninstall them all (one by one).

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.

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

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

:

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

本文标签: