Error: The 'brew link' step did not complete successfully
Solution 1
The homebrew package for node.js now includes npm again, so this happened to me when I missed the homebrew package's message about removing the standalone version first.
Assuming, like me, you've already broken node/npm by attempting the upgrade before knowing to npm uninstall npm -g
first, you can rm -rf /usr/local/lib/node_modules/npm
and then brew link node
. This removes the standalone self-hosted npm package (rather than the one brew would like to install) and lets brew symlink its bundled one from Cellar.
Solution 2
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
Solution 3
sudo chown -R $(whoami) /usr/local
would do just fine as mentioned in the brew site troubleshooting
https://github.com/Homebrew/homebrew/wiki/troubleshooting
Solution 4
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.
Solution 5
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
Related videos on Youtube
Comments
-
chandlervdw almost 2 years
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.-
pixel 67 over 11 yearsI can't get automake. mongodb and node to link with homebrew
-
-
natevw over 11 yearsDoesn't this remove the NEW npm that brew is trying to install? Following this left me without a working npm installed, whereas deleting the OLD npm folder as in my answer works.
-
Christoffer about 11 yearsTook some time, but just what I needed to do. Thanks :)
-
Caroline about 11 yearsit looks to me like you're trying to remove the new package too - whereas surely it's the old one that needs removing? I actually found that there was a symlink left over for /usr/local/bin/npm
-
kflorence over 10 yearsThank you. I had to do this in combination with the highest voted answer to get it working properly.
-
kflorence over 10 yearsAfter you remove npm you need to close and re-open your terminal to remove it from your path in order for linking to work properly, as @dain mentioned in his comment.
-
LWZ over 10 yearsI have the same problem with
aspell
. How do I find the conflicting files and directories? -
rdrobinson3 over 10 yearsThis finally worked for me. I was getting issues after i tried to install node via brew after already having npm installed. It essentially broke npm for me. I had to rm -rf the npm folder then install via brew (npm uninstall no longer worked for me). After that the rest of the steps worked perfectly.
-
Richard Tuttle about 10 yearsI had the same issue. This can apparently occur if you run "make install" for some other app manually. I had recently done just that and the solution was to chown like you did.
-
Ricky Mutschlechner about 10 yearsThanks! This helped me a lot and fixed my problem. +1
-
Coach Roebuck about 10 yearsThis worked for me. In my case, I couldn't link Elixir and Erlang during an upgrade. The directories of concern were not owned by my username, but owned by "root". I decided to delete those directories and reinstall.
-
mauricioSanchez almost 10 yearsWorked for me as well! Thanks so much!
-
songololo almost 10 yearsWorked for me... though I had to remove the node_modules (ending in 's') directory...
-
loverboy almost 10 yearsWorks for me. The key of this solution is to uninstall/remove everything so you can do a fresh install.
-
AhsenBaig over 9 yearsThe numbers aren't formatting correctly... but the steps are there. Will correct the formatting issue tomorrow.
-
Schleichermann over 9 yearsHad to remove node_modules as well, but it did the trick. Thanks a ton! +1
-
Kyle over 9 yearsYou sir are top notch.
-
getWeberForStackExchange over 9 yearsI'm surprised that they recommend this. Wouldn't it be better to do:
sudo chmod -R g+w /usr/local
(although honestly, both scare me) -
Rog over 9 yearsThis should become the accepted answer. Relevant for Yosemite too.
-
bobmagoo over 9 years
sudo chmod 777
This is never the right solution, if you're having permissions issues, investigate why they are occurring and set the minimum level of permissions required to do the job. This command will allow the file to be modified by anyone on the system. -
SuperUberDuper over 9 yearswhen I try link node I get: *Error: No such keg: /usr/local/Cellar/node *| any ideas?
-
Bede Constantinides about 9 yearsBrilliant. Thank you. Although I had no perms issues running
brew link node
for the first time. -
marcacyr almost 9 yearsTop answer didn't work out for my particular situation - this one did. Thanks for putting this up. +1
-
jeffdill2 almost 9 yearsWorked for me. Thank you!
-
Brandon Clapp almost 9 yearsAfter trying to upgrade npm, I spent an hour trying to figure this out. Brew would not let me link until the standalone version was removed first. Recommendations from nate worked for me.
-
stevek-pro over 8 yearsThis should be the answer!
-
f1lt3r over 8 years@getWeberForStackExchange I tried what you said but it didn't make a difference for me. Any ideas why that might be?
-
Jason Short over 8 yearsRather than chmod that directory I just took ownership of it. chown myuser -R -v /usr/local/lib/dtrace/ I also had the problem that dtrace didn't exist as a directory. The error was the same, but no directory was present.
-
getWeberForStackExchange over 8 years@AlistairMacDonald You've probably worked this out by now, but I'd probably need more info to work out why you were having trouble. Changing the ownership of everything in /usr/local is supposed to allow the current user to create the node links in the /usr/local structure. I was proposing to just change the group permissions of every file instead of ownership, which is slightly less crazy. My command assumed that your user is part of the group that owns all of /usr/local. It's also possible that there are different groups in /usr/local, which would require a
chgrp
command. -
marciokoko about 8 yearsHow do i reinstall npm? Or does it get installed with brew install node?
-
natevw about 8 years@marciokoko It should get installed via
brew install node
, only for some time years ago did brew leave npm out afaik. -
marciokoko about 8 years@natevw Thanks. I think what happened was a version conflict or install conflict.
-
fyngyrz almost 8 yearsI installed home-brew under OS X 10.11 specifically to get midnight commander and wget. I do not have npm installed. The "brew link" step failed as described in the question during the mc install. This answer worked for me; I made the change, re-ran the link with "brew link midnight-commander", which then ran fine. After that, typing "mc" at the command line brought up midnight commander as expected. After that, "brew install wget" worked with no fanfare. Great answer.
-
Chris Prince over 7 yearsI also had to do something like
sudo chown -R $USER:admin /usr/local/share/systemtap/tapset
-
jchnxu over 7 yearsthis command is recommended by
brew doctor
, but I prefersudo su
, execute the commands then close the terminal -
straubcreative about 7 yearsThis worked for me too, however I had to run this chown command to finally allow the link. sudo chown -R
whoami
/usr/local Sauce -
prototype almost 7 years
brew postinstall node
was the ticket -
App Dev Guy almost 7 yearsStep 3: Open a new terminal and install node - do this. Seemingly very important
-
Roy Goode about 6 yearsWorked for me! Top answer!
-
ankitkpd about 6 yearsTo remove node everywhere on your mac I followed this article: stackabuse.com/how-to-uninstall-node-js-from-mac-osx
-
ValRob about 6 yearsLinking /usr/local/Cellar/node/10.0.0...
Error: Could not symlink include/node/openssl/archs/BSD-x86_64/asm/crypto/buildinf.h /usr/local/include/node/openssl/archs/BSD-x86_64/asm/crypto is not writable
I tried, but failed -
PKHunter almost 6 yearsWhen I run
brew link --overwrite --dry-run node
, I see the errorNo such keg: /usr/local/Cellar/node
. What am I missing? -
bluesmoon almost 6 yearsNote that this is no longer possible on MacOS. No one, not even root can
chown
orchgrp
/usr
or anything under it. -
mbdavis almost 5 years
chown: /usr/local: Operation not permitted
¯_(ツ)_/¯ -
Dani Amsalem about 4 yearsThis was the ticket! For some reason, I had to run brew upgrade 2X and on the second time it asked me to install an update to XCode. Between
brew link --overwrite node
and the final command, it all seems to work. The final command you suggested doesn't work because of 'sudo. Instead, usebrew postinstall node
-
Motti Strom about 3 years
brew cleanup
nowadays