I'm Getting Errors When I Try to do 'brew update' 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 `&lt;top (required)&gt;'
    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 `&lt;top (required)&gt;'
    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 `&lt;main&gt;'


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 `&lt;top (required)&gt;'
    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 `&lt;top (required)&gt;'
    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 `&lt;main&gt;'


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.
I've similar problems and my research suggests resetting your local version of the brew repo:

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


I'm about to try this myself.