4

I want to install a gem. The instructions strongly suggest that I use Homebrew to install the gem dependencies. I have not used Homebrew a lot, maybe once years ago. I do remember that El Capitan already has it installed. I also remembered the 'brew doctor' and 'brew update' commands. First I ran brew update and got the following error:

[~]$ brew update
warning: unable to unlink CONTRIBUTING.md: Permission denied
warning: unable to unlink SUPPORTERS.md: Permission denied
fatal: cannot create directory at '.github': Permission denied
Error: Failure while executing: git pull -q origin refs/heads/master:refs/remotes/origin/master

I had no idea about the details of this error so I decided to try sudo brew update. I got the following error.

[~]$ sudo brew update
sudo: /private/etc/sudoers.d is owned by uid 501, should be 0
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:15:in `<main>'

Then I decided to run brew doctor. I got the following error.

[~]$ brew doctor
/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:15:in `<main>'

I guess the ruby version 2.0.0 is the version of Ruby that my Mac Mini Server is using for the OS. I'm using a newer version of Ruby with Ruby Version Manager for my Ruby on Rails applications.

The last time I used Homebrew it was either with Mavericks or Mountain Lion. I have no idea where to go from here to solve this problem. None of the documentation I have found online addresses this specific error.

  • You might have 2 issues one is the sudoers file has the wrong owner only edit it by visudo – mmmmmm Mar 21 '16 at 23:22
  • "I do remember that El Capitan already has it installed." Can you elaborate? – techraf Mar 22 '16 at 2:44
  • @techraf I did a clean install on El Capitan after wiping my hard drive clean. When I attempted to install homebrew it said it was already installed. There were several times when I opened Xcode it said it was installing needed components.I assumed Homebrew was installed in El Capitan or Xcode. – Pamela Cook - LightBe Corp Mar 22 '16 at 21:35
1

Why not make a list of the things you might have installed:

 brew list

Then make a backup (just in case). Then uninstall homebrew and possibly everything else in /usr/local to get a clean install and a clean start?

| improve this answer | |
  • 1
    the brew list command gives the same error. – Pamela Cook - LightBe Corp Mar 23 '16 at 1:08
  • I went ahead and uninstalled and reinstalled Homebrew as I had not used it to install anything I was currently using. I have to remove /usr/local/include manually. Now my system is ready to brew. Thanks! – Pamela Cook - LightBe Corp Mar 23 '16 at 1:50
4

I've similar problems and my research suggests resetting your local version of the brew repo:

cd $(brew --prefix) && git fetch && git reset --hard origin/master

I'm about to try this myself.

| improve this answer | |
  • on El Capitan, I still get: fatal: cannot create directory at '.github': Permission denied – rfabbri May 26 '16 at 12:37
3

As mentioned here: https://github.com/Homebrew/legacy-homebrew/issues/49879#issuecomment-196294820

What worked for me given all the errors was

sudo chown -R $(whoami):admin /usr/local
cd $(brew --prefix) && git fetch origin && git reset --hard origin/master

Then I could run brew commands again, such as brew update and brew upgrade. (And fwiw, as an alternative to brew list if it weren't working and you just wanted a quick list, you can get a crude listing just by doing ls -l cd $(brew --prefix)/Cellar)

| improve this answer | |
  • is it sensible to make system-wide /usr/local owned by a specific user as homebrew does? I cringe, but it must have a rationale. – rfabbri May 26 '16 at 12:51
3

Building off of the previous answer, run the following:

sudo chown $(whoami):admin /usr/local
cd $(brew --prefix) && git fetch origin && git reset --hard origin/master
brew update

I just ran that on El Capitan 10.11.6, and the update ended with the message:

==> Migrating HOMEBREW_REPOSITORY (please wait)...
==> Migrated HOMEBREW_REPOSITORY to /usr/local/Homebrew!
Homebrew no longer needs to have ownership of /usr/local. If you wish you can
return /usr/local to its default ownership with:

sudo chown root:wheel /usr/local

If you see that, run the command to correctly return the permission change you made at the beginning to normal.

| improve this answer | |

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .