How do I completely uninstall Node.js, and reinsta

2018-12-31 02:08发布

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.

18条回答
初与友歌
2楼-- · 2018-12-31 02:19

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
查看更多
刘海飞了
3楼-- · 2018-12-31 02:19

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

rm -rf /usr/local/share/man/man1/npm*
查看更多
路过你的时光
4楼-- · 2018-12-31 02:20

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.

查看更多
查无此人
5楼-- · 2018-12-31 02:22

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

查看更多
查无此人
6楼-- · 2018-12-31 02:24

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.*
查看更多
听够珍惜
7楼-- · 2018-12-31 02:27

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.

查看更多
登录 后发表回答