2
votes

I'm in the process of uninstalling and reinstalling node and npm on my MacBook.

So far I've done:

  1. sudo rm -rf /usr/local/lib/node_modules/npm/
  2. brew uninstall node
  3. brew unlink node
  4. sudo rm -rf [any and all node-related files and directories]
  5. brew doctor
  6. brew prune
  7. brew install node
  8. brew link node

Every step works fine up until the link. When I try brew link --overwite node, I get this error:

Linking /usr/local/Cellar/node/0.10.33...

Error: Could not symlink include/node/ares.h /usr/local/include/node is not writable.

Here's the related stack overflow: How do I completely uninstall Node.js, and reinstall from beginning (Mac OS X)

It may be a matter of tweaking the sequence. Has anyone gone through the process and have any tips? I noticed someone has already tried to install node on the production laptop I'm also using and run into the identical brew link error.

3
I've used nvm with good successVadim

3 Answers

4
votes

Try sudo chown -R $(whoami) /usr/local/ then rerun brew link --overwrite node

edit This is the same problem I had the last two times I had to brew link node and it solved my problem.

^^^^^^^^^^^^^^^^^^^^^^^

This is what not to do. Although it does work for the question given, it is reckless. Don't believe everything you read on the internet like I used to. ;) Below are a number of ways to uninstall node.js from OSX in general followed by a better way to solve the problem presented in this question. All of this was found with google... and usually lead me back to StackOverflow. The basic idea being that everything needs to go.

NPM(Safest)

sudo npm uninstall npm -g Removes all files.

sudo rm -rf /usr/local/lib/node \ /usr/local/include/node \ /usr/local/lib/node_modules \ /usr/local/include/node_modules \ /var/db/receipts/org.nodejs.* Removes extraneous bash pathnames.

If You Installed From The Node.js Website

sudo rm -rf /usr/local/{bin/{node,npm},lib/node_modules/npm,lib/node,share/man/*/node.*}

A Script You Can Try(w/ homebrew)

This one is updated more frequently then the next one listed below and is very methodical. It does attempt to use some brew commands so dont use it if you don't use homebrew. It does have a list of all problem directories, which is nice. Source. More info. Ignore the suggestion for the chown command at the end as removal of node should be done without changing permissions of critical system directories.

  1. curl -O https://raw.githubusercontent.com/DomT4/scripts/master/OSX_Node_Removal/terminatenode.sh
  2. chmod +x /path/to/terminatenode.sh
  3. ./terminatenode.sh

Another Script You Can Try

This gist was created by NiceRobot. Gist is here. Please read it before you run it to make sure you're comfortable running this script. It does require sudo as all of these options do.

  1. curl -ksO https://gist.github.com/nicerobot/2697848/raw/uninstall-node.sh Downloads the script.
  2. chmod u+x ./uninstall-node.sh Enables execution of the script by you.
  3. ./uninstall-node.sh Runs the script
  4. which node Checks to see if node is still installed. If so, choose another option.
  5. rm uninstall-node.sh Deletes the script.

The specific problem presented by this question can be dealt with with the following. Thanks for everyone's comments/recommendations. Hope all this helps someone now that all this can be found in one answer.

sudo rm -rf /usr/local/include/node

sudo rm -rf /usr/local/include/node_modules

References

  1. NiceRobot
  2. Another Q&A on StackOverflow
  3. This website.
0
votes

This post is a little stale, but I've followed the recommendations here for how to uninstall Node.js with little success. Deleting the node and node_modules in /usr/local/lib and /usr/local/include didn't do it for me, and I don't have homebrew installed. In the end it really ends up being pretty simple.

Check your path variable - in terminal enter:

echo $PATH

Go to each directory in the list that is emitted, and start deleting out anything named node or node_modules. After each one check to see if you've uninstalled it; simply attempting to check the version of Node.js should suffice - in terminal enter:

node -v

While it is installed you'll see a version emitted. When you see some other message (perhaps "file or directory not found") you know you've uninstalled it manually.

At the time of this post I can download an installer on nodejs.org, which seems to install the latest version okay.

0
votes

Try this and use nvm to reinstall it. NVM give you the option to install any node version that you need.