csdnceshi62
2012-06-24 13:40
采纳率: 100%
浏览 2.7k

如何完全卸载 Node.js 并从头重新安装(macosx)

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.

转载于:https://stackoverflow.com/questions/11177954/how-do-i-completely-uninstall-node-js-and-reinstall-from-beginning-mac-os-x

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

17条回答 默认 最新

  • 谁还没个明天 2012-06-24 14:04
    已采纳

    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.

    打赏 评论
  • 七度&光 2013-08-14 20:26

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

    打赏 评论
  • ~Onlooker 2014-01-17 23:26

    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

    打赏 评论
  • elliott.david 2014-07-07 13:40

    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.*
    
    打赏 评论
  • ~Onlooker 2014-09-20 12:13

    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
    
    打赏 评论
  • Lotus@ 2014-11-13 22:19

    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.
    打赏 评论
  • csdnceshi62 2015-01-09 22:02

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

    rm -rf /usr/local/share/man/man1/npm*
    
    打赏 评论
  • YaoRaoLov 2015-02-09 10:36

    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.

    打赏 评论
  • ~Onlooker 2015-03-11 16:18

    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.

    打赏 评论
  • 撒拉嘿哟木头 2015-05-29 03:06

    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
    
    打赏 评论
  • 乱世@小熊 2015-06-28 17:24
    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

    打赏 评论
  • python小菜 2015-07-22 20:11

    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
    
    打赏 评论
  • 谁还没个明天 2016-05-04 05:57

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

    打赏 评论
  • 胖鸭 2016-12-09 11:00

    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.

    打赏 评论
  • Lotus@ 2017-01-25 18:42

    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.

    打赏 评论
  • Lotus@ 2018-08-23 15:39

    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
    
    打赏 评论
  • 七度&光 2018-08-24 23:52

    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.

    打赏 评论

相关推荐 更多相似问题