如何完全卸载Node.js,然后从头开始重新安装(Mac OS X)

本文翻译自: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. 我的节点版本始终是v0.6.1-pre,即使我安装了brew节点并且NVM也安装了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这样说(我在一个bash终端中第一次安装了一个版本的节点之后):

nvm ls
v0.6.19
current:    v0.6.19

But when I restart bash, this is what I see: 但是当我重新启动bash时,这是我看到的:

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? 那么这个幻影节点0.6.1-pre版本在哪里,我该如何摆脱它? I'm trying to install libraries via NPM so that I can work on a project. 我正在尝试通过NPM安装库,以便可以在项目上工作。

I tried using BREW to update before NVM, using "brew update" and "brew install node". 我尝试使用BREW在NVM之前进行更新,使用“ brew update”和“ 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". 我尝试删除/ usr / local / include中的“节点”目录以及“ / usr / local / lib”中的“节点”和“ node_modules”。 I've tried uninstalling npm and reinstalling it following these instructions. 我已尝试按照以下说明卸载npm并重新安装。

All of this because I was trying to update an older version of node to install the "zipstream" library. 所有这些都是因为我试图更新节点的旧版本以安装“ zipstream”库。 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. 现在,我的用户目录中有文件夹,并且节点版本STILL不是最新的,即使NVM表示它正在使用0.6.19。

Ideally, I'd like to uninstall nodejs, npm, and nvm, and just reinstall the entire thing from scratch on my system. 理想情况下,我想卸载nodejs,npm和nvm,然后从头开始重新安装整个系统。


#1楼

参考:https://stackoom.com/question/ktta/如何完全卸载Node-js-然后从头开始重新安装-Mac-OS-X


#2楼

Apparently, there was a /Users/myusername/local folder that contained a include with node and lib with node and node_modules . 显然,存在一个/Users/myusername/local文件夹,其中包含一个include nodelib以及nodenode_modules How and why this was created instead of in my /usr/local folder, I do not know. 我不知道是如何以及为什么创建它的,而不是在我的/usr/local文件夹中创建的。

Deleting these local references fixed the phantom v0.6.1-pre. 删除这些本地引用可修复幻影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: 要完全卸载node + npm,请执行以下操作:

  1. go to /usr/local/lib and delete any node and node_modules 转到/ usr / local / lib并删除任何节点node_modules
  2. go to /usr/local/include and delete any node and node_modules directory 转到/ usr / local / include并删除任何nodenode_modules目录
  3. if you installed with brew install node , then run brew uninstall node in your terminal 如果你安装了冲泡安装节点 ,然后在你的终端上运行的BREW卸载节点
  4. check your Home directory for any local or lib or include folders, and delete any node or node_modules from there 检查主目录中是否有任何本地lib包含文件夹,并从此处删除任何节点node_modules
  5. go to /usr/local/bin and delete any node executable 转到/ usr / local / bin并删除任何节点可执行文件

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 . 另外,NVM修改$HOME/.bashrc的PATH变量,该变量必须手动还原

Then download nvm and follow the instructions to install node. 然后下载nvm并按照说明安装节点。 The latest versions of node come with npm , I believe, but you can also reinstall that as well. 我相信node的最新版本是npm附带的,但是您也可以重新安装它。


#3楼

I have been hit by an issue during uninstall of Node.js on my mac. 在Mac上卸载Node.js时遇到问题。 I had some strange behavior like npm is still their even after having removing it with all this. 即使删除了所有这些内容,我仍然有一些奇怪的行为,例如npm仍然是他们的行为。

It was because I had an old install done with macport. 这是因为我用macport完成了旧安装。 So you also have to uninstall it using port: 因此,您还必须使用port卸载它:

sudo port uninstall nodejs

It may have install many different versions of Node.js so uninstall them all (one by one). 它可能安装了许多不同版本的Node.js,因此(一一卸载)它们。


#4楼

On Mavericks I install it from the node pkg (from nodejs site) and I uninstall it so I can re-install using brew. 在Mavericks上,我从node pkg(从nodejs站点)安装它,并卸载了它,因此可以使用brew重新安装。 I only run 4 commands in the terminal: 我只在终端中运行4个命令:

  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 如果仍然有节点安装,请重复步骤2。一切正常之后,我将使用brew install node进行brew install node


#5楼

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. 我知道这篇文章有些过时,但是只是想分享删除Node.js时在Terminal中对我有用的命令。

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 更新: 23 SEP 2016


If you're afraid of running these commands... 如果您担心运行这些命令...

Thanks to jguix for this quick tutorial . 感谢jguix提供了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) 手动检查您的文件(位于Home文件夹中)

 ~/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 适用于10.10.5及以上

Thanks Lenar Hoyt 感谢Lenar Hoyt

Gist Comment Source: gistcomment-1572198 要点评论来源: gistcomment-1572198

Original Gist: TonyMtz/d75101d9bdf764c890ef 原始要点: 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.*

#6楼

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
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章