Homebrew无法继续酿造了。

30

在我的MacMini电脑上运行El Capitan操作系统时,我无法再使用brew命令。我遇到了以下错误:

/usr/local/Library/Homebrew/config.rb:34:in `initialize': no implicit conversion of nil into String (TypeError)
    from /usr/local/Library/Homebrew/config.rb:34:in `new'
    from /usr/local/Library/Homebrew/config.rb:34:in `<top (required)>'
    from /Library/Ruby/Site/2.0.0/rubygems/core_ext/kernel_require.rb:54:in `require'
    from /Library/Ruby/Site/2.0.0/rubygems/core_ext/kernel_require.rb:54:in `require'
    from /usr/local/Library/Homebrew/global.rb:18:in `<top (required)>'
    from /Library/Ruby/Site/2.0.0/rubygems/core_ext/kernel_require.rb:54:in `require'
    from /Library/Ruby/Site/2.0.0/rubygems/core_ext/kernel_require.rb:54:in `require'
    from /usr/local/Library/brew.rb:10:in `<main>'

/usr/local的权限正确。

我没有改变的config.rb文件看起来像这样:

def cache
  if ENV["HOMEBREW_CACHE"]
    Pathname.new(ENV["HOMEBREW_CACHE"]).expand_path
  else
    # we do this for historic reasons, however the cache *should* be the same
    # directory whichever user is used and whatever instance of brew is executed
    home_cache = Pathname.new("~/Library/Caches/Homebrew").expand_path
    if home_cache.directory? && home_cache.writable_real?
      home_cache
    else
      Pathname.new("/Library/Caches/Homebrew").extend Module.new {
        def mkpath
          unless exist?
            super
            chmod 0775
          end
        end
      }
    end
  end
end

HOMEBREW_CACHE = cache
undef cache

# Where brews installed via URL are cached
HOMEBREW_CACHE_FORMULA = HOMEBREW_CACHE+"Formula"

unless defined? HOMEBREW_BREW_FILE
  HOMEBREW_BREW_FILE = ENV["HOMEBREW_BREW_FILE"] || which("brew").to_s
end

# Where we link under
HOMEBREW_PREFIX = Pathname.new(ENV["HOMEBREW_PREFIX"])

# Where .git is found
HOMEBREW_REPOSITORY = Pathname.new(ENV["HOMEBREW_REPOSITORY"])

HOMEBREW_LIBRARY = Pathname.new(ENV["HOMEBREW_LIBRARY"])
HOMEBREW_CONTRIB = HOMEBREW_REPOSITORY/"Library/Contributions"

# Where we store built products
HOMEBREW_CELLAR = Pathname.new(ENV["HOMEBREW_CELLAR"])

HOMEBREW_LOGS = Pathname.new(ENV["HOMEBREW_LOGS"] || "~/Library/Logs/Homebrew/").expand_path

HOMEBREW_TEMP = Pathname.new(ENV.fetch("HOMEBREW_TEMP", "/tmp"))

unless defined? HOMEBREW_LIBRARY_PATH
  HOMEBREW_LIBRARY_PATH = Pathname.new(__FILE__).realpath.parent.join("Homebrew")
end

HOMEBREW_LOAD_PATH = HOMEBREW_LIBRARY_PATH

使用brew、brew doctor、brew update等命令时都会出现相同的错误。

有任何想法,可能出了什么问题吗?


你能否编辑你的问题,加上 more /usr/local/Library/Homebrew/config.rb - Thomas Ayoub
5个回答

55

我遇到了相同的问题 - 似乎是由于权限问题导致无法完成brew更新的结果。

首先,我将库重置为最新版本:

cd /usr/local/bin
git reset --hard HEAD

那么我就可以运行:

brew doctor

发现了权限问题。按照说明修复这些权限最终允许我运行:

brew update

2
这很可能也是我的问题原因。Sophos的旧版本在/usr/local/bin和/usr/local/share中搞乱了权限。仅使用sudo chown -R $(whoami) /usr/local/bin和.../share更新权限并没有帮助我。 - Arwed
是的,我的问题也是从Sophos开始的。而且一直持续着 :| - gollyg
1
您需要 Sophos 9.4,它仍处于预览状态。 - Arwed
在执行上述步骤后,我收到了数百条这样的消息:错误:无法导入:xxxxyyyzzz undefined method 'desc' for Formulary::Formulae::XxxxYyyZzz:Class,所以我 cd ~ 然后再次尝试,一切都很顺利!好提示,帮了我大忙。 - harperville

6

每次更新 OS X 都会破坏权限。

尝试以下方法:

sudo chown -R $(whoami) /usr/local/share/man/man1

并且

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

确保当前用户(运行brew的用户)有权限访问/usr/local


1
在我的情况下,不是OSX搞乱了权限,而是Sophos。版本9.4.1修复了这个错误。 - Arwed
很有趣!我有Sohpos 9.2.9,它没有引起问题。虽然我的不是家庭版。 - Pouria

2

0

有点麻烦,但我刚刚卸载了 Homebrew 并重新安装。警告:这将卸载所有使用 brew 安装的软件包。

$ ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/uninstall)"
$ sudo chown -R $USER /usr/local/
$ ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

1
这正是我需要避免的。 - Arwed

0
对我有用的是运行 brew upgrade (而不是 brew update)。您可能会遇到一些权限问题,如其他答案中所提到的。它会建议一些命令来修复这个问题。
在权限问题得到解决后,运行 brew upgrade 就可以解决这个问题。当更新操作系统时,显然这不是一个罕见的问题 - 在 Homebrew官方文档 上阅读有关它的内容。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接