88

I am trying to install memcached using:

brew install memcached

This ends in error about homebrew not being able to create a symlink:

The linking step did not complete successfully
The formula built, but is not symlinked into /usr/local

Help!

septerr
  • 6,445
  • 9
  • 50
  • 73

6 Answers6

121

I uninstalled what homebrew had so far installed (libevent dependency):

brew uninstall libevent

Then chow-ned the usr/local directory:

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

Then tried to install memcached again and it worked:

brew install memcached
JasonDScott
  • 247
  • 2
  • 9
septerr
  • 6,445
  • 9
  • 50
  • 73
  • 1
    Saved me from my nightmare! THANKS! – 0bserver07 Apr 11 '14 at 00:01
  • This also helped me with "irssi" - Thanks – Joe T Jul 22 '14 at 19:18
  • 1
    still works! Note the septerr needs to change to your username – thiswayup May 17 '16 at 08:41
  • When trying to "brew install memcached", you get the following error: Not working: curl: (22) The requested URL returned error: 404 Not Found. Error: Failed to download resource "libevent" Download failed: https://downloads.sourceforge.net/project/levent/libevent/libevent-2.0/libevent-2.0.22-stable.tar.gz – desloovere_j May 30 '16 at 15:21
  • Can you @JasonDScott explain what exactly these commands do? – ARK Sep 13 '16 at 19:43
  • @akshayrajkore `sudo chown -R $(whoami) /usr/local` recursively changes ownership of the directory so that your user does not need admin permissions to write to that folder or any files it contains, which is where brew is trying to write to. – JasonDScott Sep 17 '16 at 06:39
  • 22
    your chown command is no longer supported in High Sierra. Use `sudo chown -R $(whoami) $(brew --prefix)/*`instead – PetrykowskiM Mar 16 '18 at 14:15
  • 2
    chown: /usr/local: Operation not permitted – Rodrigo Vieira Mar 29 '19 at 18:05
100

As of High Sierra, /usr/local is no longer chown-able. The new procedure suggested in a Homebrew issue is:

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

FYI: If required /usr/local subfolders (e.g. ./include or ./Frameworks) are missing, you'll have to mkdir them first

Sean DeNigris
  • 6,306
  • 1
  • 31
  • 37
25

Thanks for updating your own question this helped me a lot. I fixed this issue by making all locations in /usr/local writable to group as I am already in the admin group.

To do this just use the following command

sudo chmod -R g+w /usr/local
Matko
  • 3,386
  • 4
  • 21
  • 35
iain
  • 10,798
  • 3
  • 37
  • 41
7

after i performed the suggestions in @septerr answer, i still was unable to install carthage via homebrew... after some googleing i found this: Gist https://gist.github.com/dalegaspi/7d336944041f31466c0f9c7a17f7d601

Anyway... got this:

Error: An unexpected error occurred during the 'brew link' step The formula built, but is not symlinked into /usr/local Permission denied @ dir_s_mkdir - /usr/local/Frameworks Error: Permission denied @ dir_s_mkdir - /usr/local/Frameworks

did this:

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

and

sudo install -d -o $(whoami) -g admin /usr/local/Frameworks

after that is was able to install carthage successfully

Darkglow
  • 683
  • 2
  • 8
  • 18
3

It seems that since El Capitan the file permissions in /usr/local have been changed, causing the above problem for me.

Instead of the chosen solution I suggest to do a:

sudo chown -R :staff /usr/local

This will work for all users

Morris
  • 593
  • 7
  • 7
1

Symlink errors prevented

brew install pyenv

on macOS Big Sur 11.6.2.

Solution suggested by @sean-denigris worked

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

Before this I had tried the solution proposed by @marko

sudo chmod -R g+w /usr/local

that gave the following error

chmod: Unable to change file mode on /usr/local: Operation not permitted

ugmurthy
  • 49
  • 6