无法更新MAC OS X el capitan中的brew并通过`require`不断出现Load错误。


69

我不确定为什么会这样,但是我无法在我的MAC OS X El Capitan中更新brew。我做了:

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

为了解决这个问题,我对上面的命令进行了修改,但又遇到了更多的问题:

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>'

现在,每当我进行Brew安装时,我都会得到:

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>'

实际上,似乎无论何时我做任何事情,例如键入brew,都会得到相同的消息。有谁知道如何解决这一问题?


2
这可能是一个超级hacky解决方案,但我完全卸载了自制软件,然后重新安装了它。要卸载,请阅读:quora.com/How-does-one-uninstall-Homebrew
Charlie Parker


自制软件已更新,可以解决/usr/local所有权问题。如果您有一段时间没有更新Homebrew,请按照下面@bfontaine概述的步骤进行。更新后,您可以root:wheel通过运行来恢复所有权,sudo chown root:wheel /usr/local并继续使用和更新Homebrew,而不必担心文件所有权。
Sandeep M

Answers:


249

您不应该sudo与Homebrew一起使用。首先运行以下命令以确保您拥有以下所有内容/usr/local

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

较新的macOS版本的替代命令:

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

然后将您的自制软件仓库重置为干净状态:

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

它应该解决您的问题。

(如果在其他位置安装了Homebrew,请替换/usr/local$(brew --prefix)


3
我跑了,sudo chown -R $(whoami):admin /usr/local但是终端什么也没输出。我应该看什么?
查理·帕克

您确定要更改对其中的用户的所有权/usr/local吗?即使可行,这对我来说还是非常错误的。
龙猫

1
@CharlieParker- unix filesystem layout> en.wikipedia.org/wiki/Filesystem_Hierarchy_Standard
龙猫

2
在GithubHomebrew FAQ中找到了此文件,我认为它与以下答案有关:“为什么Homebrew偏爱我安装/usr/local?... 3. Apple安全地将目录留给了我们。这意味着没有/usr/local目录默认情况下,因此无需担心将现有工具弄乱。”
alondono '16

1
brew update之后,您可能还需要修复问题。
Dmytro Korduban '16
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.