Error: The 'brew link' step did not complete successfully

201,810

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

Share:
201,810

Related videos on Youtube

chandlervdw
Author by

chandlervdw

Cool guy doing cool stuff trying to be cool.

Updated on July 17, 2022

Comments

  • chandlervdw
    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
      pixel 67 over 11 years
      I can't get automake. mongodb and node to link with homebrew
  • natevw
    natevw over 11 years
    Doesn'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
    Christoffer about 11 years
    Took some time, but just what I needed to do. Thanks :)
  • Caroline
    Caroline about 11 years
    it 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
    kflorence over 10 years
    Thank you. I had to do this in combination with the highest voted answer to get it working properly.
  • kflorence
    kflorence over 10 years
    After 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
    LWZ over 10 years
    I have the same problem with aspell. How do I find the conflicting files and directories?
  • rdrobinson3
    rdrobinson3 over 10 years
    This 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
    Richard Tuttle about 10 years
    I 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
    Ricky Mutschlechner about 10 years
    Thanks! This helped me a lot and fixed my problem. +1
  • Coach Roebuck
    Coach Roebuck about 10 years
    This 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
    mauricioSanchez almost 10 years
    Worked for me as well! Thanks so much!
  • songololo
    songololo almost 10 years
    Worked for me... though I had to remove the node_modules (ending in 's') directory...
  • loverboy
    loverboy almost 10 years
    Works for me. The key of this solution is to uninstall/remove everything so you can do a fresh install.
  • AhsenBaig
    AhsenBaig over 9 years
    The numbers aren't formatting correctly... but the steps are there. Will correct the formatting issue tomorrow.
  • Schleichermann
    Schleichermann over 9 years
    Had to remove node_modules as well, but it did the trick. Thanks a ton! +1
  • Kyle
    Kyle over 9 years
    You sir are top notch.
  • getWeberForStackExchange
    getWeberForStackExchange over 9 years
    I'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
    Rog over 9 years
    This should become the accepted answer. Relevant for Yosemite too.
  • bobmagoo
    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
    SuperUberDuper over 9 years
    when I try link node I get: *Error: No such keg: /usr/local/Cellar/node *| any ideas?
  • Bede Constantinides
    Bede Constantinides about 9 years
    Brilliant. Thank you. Although I had no perms issues running brew link node for the first time.
  • marcacyr
    marcacyr almost 9 years
    Top answer didn't work out for my particular situation - this one did. Thanks for putting this up. +1
  • jeffdill2
    jeffdill2 almost 9 years
    Worked for me. Thank you!
  • Brandon Clapp
    Brandon Clapp almost 9 years
    After 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
    stevek-pro over 8 years
    This should be the answer!
  • f1lt3r
    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
    Jason Short over 8 years
    Rather 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
    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
    marciokoko about 8 years
    How do i reinstall npm? Or does it get installed with brew install node?
  • natevw
    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
    marciokoko about 8 years
    @natevw Thanks. I think what happened was a version conflict or install conflict.
  • fyngyrz
    fyngyrz almost 8 years
    I 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
    Chris Prince over 7 years
    I also had to do something like sudo chown -R $USER:admin /usr/local/share/systemtap/tapset
  • jchnxu
    jchnxu over 7 years
    this command is recommended by brew doctor, but I prefer sudo su, execute the commands then close the terminal
  • straubcreative
    straubcreative about 7 years
    This 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
    prototype almost 7 years
    brew postinstall node was the ticket
  • App Dev Guy
    App Dev Guy almost 7 years
    Step 3: Open a new terminal and install node - do this. Seemingly very important
  • Roy Goode
    Roy Goode about 6 years
    Worked for me! Top answer!
  • ankitkpd
    ankitkpd about 6 years
    To remove node everywhere on your mac I followed this article: stackabuse.com/how-to-uninstall-node-js-from-mac-osx
  • ValRob
    ValRob about 6 years
    Linking /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
    PKHunter almost 6 years
    When I run brew link --overwrite --dry-run node, I see the error No such keg: /usr/local/Cellar/node. What am I missing?
  • bluesmoon
    bluesmoon almost 6 years
    Note that this is no longer possible on MacOS. No one, not even root can chown or chgrp /usr or anything under it.
  • mbdavis
    mbdavis almost 5 years
    chown: /usr/local: Operation not permitted ¯_(ツ)_/¯
  • Dani Amsalem
    Dani Amsalem about 4 years
    This 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, use brew postinstall node
  • Motti Strom
    Motti Strom about 3 years
    brew cleanup nowadays