69

I am not sure why this is happening but I cannot update brew in my MAC OS X El Capitan. I did:

brew update

and got:

warning: unable to unlink CONTRIBUTING.md: Permission denied
warning: unable to unlink SUPPORTERS.md: Permission denied
fatal: cannot create directory at '.github': Permission denied

to go over that issue I sudoed the above command but got further issues:

sudo brew update
Password:
/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:55:in `require': cannot load such file -- mach (LoadError)
    from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:55:in `require'
    from /usr/local/Library/Homebrew/extend/pathname.rb:2:in `<top (required)>'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:55:in `require'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:55:in `require'
    from /usr/local/Library/Homebrew/global.rb:3:in `<top (required)>'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:55:in `require'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:55:in `require'
    from /usr/local/Library/brew.rb:16:in `<main>'

now whenever I do brew install I get:

brew update

/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:55:in `require': cannot load such file -- mach (LoadError)
    from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:55:in `require'
    from /usr/local/Library/Homebrew/extend/pathname.rb:2:in `<top (required)>'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:55:in `require'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:55:in `require'
    from /usr/local/Library/Homebrew/global.rb:3:in `<top (required)>'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:55:in `require'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:55:in `require'
    from /usr/local/Library/brew.rb:16:in `<main>'

in fact, it seems that whenever I do anything, like just type brew it gets the same message. Does anyone know how to fix this?

3
  • 2
    this is probably a super hacky solution but I completely uninstalled homebrew and re-installed it. To uninstall read: quora.com/How-does-one-uninstall-Homebrew Mar 20, 2016 at 22:54
  • 1
    Possible duplicate of homebrew not working on OSX
    – Ivan Chau
    May 11, 2016 at 15:38
  • Homebrew has been updated to address the problem of /usr/local ownership. If you haven't updated Homebrew in a while, follow the steps outlined by @bfontaine below. Once updated, you may revert ownership back to root:wheel by running sudo chown root:wheel /usr/local and, continue using and updating Homebrew without worrying about file ownership.
    – Sandeep M
    Sep 11, 2017 at 17:23

1 Answer 1

249

You shouldn’t use sudo with Homebrew. First run the following to ensure you own everything under /usr/local:

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

Alternative command for newer macOS version:

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

Then reset your Homebrew repo to a clean state:

cd /usr/local && git fetch && git reset --hard origin/master

It should fix your issues.

(replace /usr/local with $(brew --prefix) if you installed Homebrew elsewhere)

16
  • 3
    I ran sudo chown -R $(whoami):admin /usr/local but the terminal outputted nothing. What was I suppose to see? Mar 21, 2016 at 23:54
  • Are you sure you really want to change ownership to a user in /usr/local? It seems very wrong to me even though it may work.
    – totoro
    Apr 16, 2016 at 14:34
  • 1
    @CharlieParker unix filesystem layout -> en.wikipedia.org/wiki/Filesystem_Hierarchy_Standard.
    – totoro
    Apr 18, 2016 at 18:31
  • 2
    I found this in the Homebrew FAQ in Github, which I think is relevant to this answer: "Why does Homebrew prefer I install to /usr/local?... 3. It’s safe Apple has left this directory for us. Which means there is no /usr/local directory by default, so there is no need to worry about messing up existing tools."
    – alondono
    May 1, 2016 at 4:23
  • 1
    You may also need brew update after that to fix stuff. Aug 15, 2016 at 14:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.