[macos] Error: The 'brew link' step did not complete successfully

I'm trying to install node.js via Homebrew. Unfortunately, I get this error:

?  ~  brew install node
==> Downloading http://nodejs.org/dist/v0.8.10/node-v0.8.10.tar.gz
######################################################################## 100.0%
==> ./configure --prefix=/usr/local/Cellar/node/0.8.10
==> make install
==> Caveats
Homebrew installed npm.
We recommend prepending the following path to your PATH environment
variable to have npm-installed binaries picked up:
  /usr/local/share/npm/bin
Warning: Could not link node. Unlinking...
Error: The `brew link` step did not complete successfully
The formula built, but is not symlinked into /usr/local
You can try again using `brew link node'
==> Summary
/usr/local/Cellar/node/0.8.10: 856 files, 13M, built in 103 seconds

So then I try to link node manually...

?  ~  brew link node
Linking /usr/local/Cellar/node/0.8.10... Warning: Could not link node. Unlinking...

Error: Could not symlink file: /usr/local/Cellar/node/0.8.10/lib/node_modules/npm/scripts/relocate.sh
Target /usr/local/lib/node_modules/npm/scripts/relocate.sh already exists. You may need to delete it.
To force the link and delete this file, do:
  brew link -f formula_name

To list all files that would be deleted:
  brew link -n formula_name

No luck, so I try forcefully linking node...

?  ~  brew link -f node
Linking /usr/local/Cellar/node/0.8.10... Warning: Could not link node. Unlinking...

Error: Permission denied - /usr/local/lib/dtrace/node.d

I'm not familiar with dtrace in any regard and I'm afraid to mess with permissions, so I tried to sudo..

? ~ git:(master) sudo brew link -f node
Password:
Error: Cowardly refusing to `sudo brew link'
You can use brew with sudo, but only if the brew executable is owned by root.
However, this is both not recommended and completely unsupported so do so at
your own risk.

I've tried uninstalling node via brew uninstall node and retrying the install with no luck.

This question is related to macos node.js npm homebrew

The answer is


I'm a bit late, what worked for me was this:

* npm uninstall npm -g

* brew uninstall node

* brew install node

* sudo rm -rf /usr/local/lib/dtrace/node.d

* brew link node (caused error with permissions)

* sudo chmod 777 /usr/local/lib/dtrace/node.d

* brew link node

Everything was successful after this sequence


I was struggling with this for a while. (for me "npm uninstall npm -g" did nothing)

I tried a bunch of things:

npm uninstall npm -g
brew uninstall node
brew install node

I was still having some issues and was getting errors when i tried to link the node files

Finally i tried this

brew link --overwrite node

That seemed to have fixed it. (it overwrites al the conflicting files and also links node and npm)

Hope this helps


Had been wrecking my head on symlinking node .. and nothing seemed to work...but finally what worked is setting the right permissions . This 'sudo chown -R $(whoami) /usr/local' did the work for me.


Try this. Got from another reference and worked for me.

brew uninstall node
brew update
brew upgrade
brew cleanup
brew install node
sudo chown -R $(whoami) /usr/local
brew link --overwrite node
brew postinstall node

I fixed this in El Capitan by using the following command. Honestly, no idea what it does, but thought I'd share since it fixed my problem.

brew link --overwrite node

My problem had a slightly different solution. The directory in which brew wanted to create the symlinks were not owned by the current user.

ls -la /usr/local/bin/lib/node | grep node yielded:

drwxr-xr-x    3 24561  wheel   102 May  4  2012 node
drwxr-xr-x    7 24561  wheel   238 Sep 18 16:37 node_modules

For me, the following fixed it:

sudo chown $(users) /usr/local/bin/lib/node_modules
sudo chown $(users) /usr/local/bin/lib/node

ps. $(users) will get expanded to your username, went a little out of my way to help out lazy copy pasters ;)


I was getting an error while installation that not able to link node and /usr/local/include is not writable

Below solution worked for me :- First create the include folder, note that this requires sudo privileges

cd /usr/local

sudo mkdir include

sudo chown -R $(whoami) $(brew --prefix)/*

brew link node

I had the same problem after transferring all my applications from my old Mac to my new one.

I found the solution by running brew doctor :

Warning: Broken symlinks were found. Remove them with brew prune

After running brew prune, Homebrew is finally back on track :)


I also managed to mess up my NPM and installed packages between these Homebrew versions and no matter how many time I unlinked / linked and uninstalled / installed node it still didn't work.

As it turns out you have to remove NPM from the path otherwise Homebrew won't install it: https://github.com/mxcl/homebrew/blob/master/Library/Formula/node.rb#L117

Hope this will help someone with the same problem and save that hour or so I had to spend looking for the problem...


Don't know, if it's a good idea or not: After trying all other solutions without success, I just renamed /usr/local/lib/dtrace, linked node and re-renamed the directory again. After that, node worked as expected.


sudo chown -R $(whoami) /usr/local 

would do just fine as mentioned in the brew site troubleshooting

https://github.com/Homebrew/homebrew/wiki/troubleshooting


I completely uninstalled brew and started again, only to find the same problem again.

Brew appears to work by symlinking the required binaries into your system where other installation methods would typically copy the files.

I found an existing set of node libraries here:

/usr/local/include/node

After some head scratching I remembered installing node at the date against this old version and it hadn't been via brew.

I manually deleted this entire folder and successfully linked npm.

This would explain why using brew uninstall or even uninstall brew itself had no effect.

The highest ranked answer puts this very simply, but I thought I'd add my observations about why it's necessary.

I'm guessing a bunch of issues with other brew packages might be caused by old non-brew instances of packages being in the way.


I have tried all of the methods and none of them works. The easiest way is to reinstall node from https://nodejs.org/en/download/

Simply download the pkg and install it. Now I have a working npm and node again.


the ultimate answer: change the owner of that directory to whoever you are

sudo chown -R `whoami` /usr/local/include

which is also recommended by brew if you run brew doctor


You probably already installed an older version of node.js using a different method, so you need to manually remove the files that are getting in brew's way.

Do brew link -n node and manually delete those conflicting files and directories, then try brew link node again.


I run Mac OS X Mavericks. I tried to install node 0.10.25 and the top answer did not work for me.

natevw says to rm -rf /usr/local/lib/node_modules/npm but if the permissions on /usr/local/lib/node_modules look like this:

drwxr-xr-x   3 root      admin   102 Feb  2 20:45 node_modules

then brew will not be able to create its npm symlink in that directory. Here's my solution:

Step 1: Update Homebrew

$ brew update

Step 2: Remove node/npm everywhere on your system

Some of these commands are not necessary depending on how you installed node/npm in the past.

$ brew uninstall npm
$ brew uninstall node
$ npm uninstall npm -g
$ sudo rm -rf /usr/local/lib/node_modules

Note: I had stray node files that I found by running brew -v link node (which gave me the verbose output of the linking errors brew was complaining about). You may need to:

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

Step 3: Open a new terminal and install node

$ brew install node

by the Finder, Delete this file:

/usr/local/lib/dtrace/node.d

in terminal:

$ brew link --overwrite --dry-run node

then:

$ brew link node

You need to remove the npm package manually.

first unlink node: brew link -n node

remove npm folder: rm -R /usr/local/Cellar/node/0.8.10/lib/node_modules/npm

link again: brew link node

there will be a soft link to the new location of npm


thx @suweller.

I fixed the problem:

?  bin git:(master) ? brew link node
Linking /usr/local/Cellar/node/0.10.25... Warning: Could not link node. Unlinking...

Error: Permission denied - /usr/local/lib/node_modules/npm

I had the same problem as suweller:

?  bin git:(master) ? ls -la /usr/local/lib/ | grep node
drwxr-xr-x   3 24561  wheel   102 11 Okt  2012 node
drwxr-xr-x   3 24561  wheel   102 27 Jan 11:32 node_modules

so i fixed this problem by:

?  bin git:(master) ? sudo chown $(users) /usr/local/lib/node_modules
?  bin git:(master) ? sudo chown $(users) /usr/local/lib/node

after i fixed this problem I got another one:

?  bin git:(master) ? brew link node
Linking /usr/local/Cellar/node/0.10.25... Warning: Could not link node. Unlinking...

Error: Could not symlink file: /usr/local/Cellar/node/0.10.25/lib/dtrace/node.d
Target /usr/local/lib/dtrace/node.d already exists. You may need to delete it.
To force the link and overwrite all other conflicting files, do:
  brew link --overwrite formula_name

To list all files that would be deleted:
  brew link --overwrite --dry-run formula_name

So I removed node.d by:

?  bin git:(master) ? sudo rm /usr/local/lib/dtrace/node.d

got another permission error:

?  bin git:(master) ? brew link node
Linking /usr/local/Cellar/node/0.10.25... Warning: Could not link node. Unlinking...

Error: Could not symlink file: /usr/local/Cellar/node/0.10.25/lib/dtrace/node.d
/usr/local/lib/dtrace is not writable. You should change its permissions.

and fixed it:

?  bin git:(master) ? sudo chown $(users) /usr/local/Cellar/node/0.10.25/lib/dtrace/node.d

and finally everything worked:

?  bin git:(master) ? brew link node
Linking /usr/local/Cellar/node/0.10.25... 1225 symlinks created

Most brew install issues with node are caused by permission errors or having node previously installed and then trying to install it via brew. The solution that worked for me finally was:

WARNING: This will uninstall nodejs (multiple versions) use with caution:

  1. Remove node via brew:

    brew uninstall node

  2. also did via force:

    brew uninstall node --force

  3. To use the script Source: Remove node:

    curl -O https://raw.githubusercontent.com/DomT4/scripts/master/OSX_Node_Removal/terminatenode.sh

Then:

chmod +x /path/to/terminatenode.sh

Then:

./terminatenode.sh .
  1. Then make sure to do the following command:

    chown $USER /usr/local

  2. Then do a brew update (keep doing this until all things are updated):

    brew update

  3. Clean brew up and run update again (might be redundant) and run doctor to make sure things are in place:

    brew cleanup; brew update; brew doctor

  4. And finally install node via brew (verbose):

    brew install -v node


Examples related to macos

Problems with installation of Google App Engine SDK for php in OS X dyld: Library not loaded: /usr/local/opt/openssl/lib/libssl.1.0.0.dylib dyld: Library not loaded: /usr/local/opt/icu4c/lib/libicui18n.62.dylib error running php after installing node with brew on Mac Could not install packages due to an EnvironmentError: [Errno 13] How do I install Java on Mac OSX allowing version switching? Git is not working after macOS Update (xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools) Can't compile C program on a Mac after upgrade to Mojave You don't have write permissions for the /Library/Ruby/Gems/2.3.0 directory. (mac user) How can I install a previous version of Python 3 in macOS using homebrew? Could not install packages due to a "Environment error :[error 13]: permission denied : 'usr/local/bin/f2py'"

Examples related to node.js

Hide Signs that Meteor.js was Used Querying date field in MongoDB with Mongoose SyntaxError: Cannot use import statement outside a module Server Discovery And Monitoring engine is deprecated How to fix ReferenceError: primordials is not defined in node UnhandledPromiseRejectionWarning: This error originated either by throwing inside of an async function without a catch block dyld: Library not loaded: /usr/local/opt/icu4c/lib/libicui18n.62.dylib error running php after installing node with brew on Mac internal/modules/cjs/loader.js:582 throw err DeprecationWarning: Buffer() is deprecated due to security and usability issues when I move my script to another server Please run `npm cache clean`

Examples related to npm

What does 'x packages are looking for funding' mean when running `npm install`? error: This is probably not a problem with npm. There is likely additional logging output above Module not found: Error: Can't resolve 'core-js/es6' Browserslist: caniuse-lite is outdated. Please run next command `npm update caniuse-lite browserslist` ERROR in The Angular Compiler requires TypeScript >=3.1.1 and <3.2.0 but 3.2.1 was found instead DeprecationWarning: Buffer() is deprecated due to security and usability issues when I move my script to another server Please run `npm cache clean` What exactly is the 'react-scripts start' command? On npm install: Unhandled rejection Error: EACCES: permission denied Difference between npx and npm?

Examples related to homebrew

dyld: Library not loaded: /usr/local/opt/openssl/lib/libssl.1.0.0.dylib dyld: Library not loaded: /usr/local/opt/icu4c/lib/libicui18n.62.dylib error running php after installing node with brew on Mac How can I install a previous version of Python 3 in macOS using homebrew? SSL_connect: SSL_ERROR_SYSCALL in connection to github.com:443 pip3: command not found env: node: No such file or directory in mac Stuck at ".android/repositories.cfg could not be loaded." Brew install docker does not include docker engine? What do raw.githubusercontent.com URLs represent? Homebrew refusing to link OpenSSL