30

On my MacMini with El Capitan I can't run brew any more. I get the following Error:

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

The permissions of /usr/local are correct.

The config.rb file, which I haven't changed looks like this:

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

The same error occurs with brew, brew doctor, brew update etc.

Any ideas, what could be wrong?

Arwed
  • 1,755
  • 3
  • 16
  • 26

5 Answers5

55

I had the same issue - seemed to be the result of a brew update that could not complete due to permissions issues.

First I reset the repo to the latest head:

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

Then I could run:

brew doctor

Which found permissions issues. Fixing those permissions as per instructions finally allowed me to run:

brew update
gollyg
  • 566
  • 4
  • 2
  • 2
    That was probably the reason for my issue too. The previous version of Sophos messed up with the permissions in /usr/local/bin and /usr/local/share. Just updating the permissions with sudo chown -R $(whoami) /usr/local/bin and .../share didn't help me. – Arwed Jan 22 '16 at 08:17
  • Yep, my issue starts with Sophos as well. And keeps doing it :| – gollyg Jan 25 '16 at 00:05
  • 1
    You need Sophos 9.4 which still is in Preview state. – Arwed Jan 26 '16 at 07:04
  • I got hundreds of these messages after performing the steps above: `Error: Failed to import: xxxxyyyzzz undefined method 'desc' for Formulary::Formulae::XxxxYyyZzz:Class` so I `cd ~` and tried it again and everything worked great! Good tip, helped me out. – harperville Feb 03 '16 at 19:19
6

OS X messes up permissions with every update.

Try this:

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

and

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

and ensure that the current user (the one running brew) has permission to access /usr/local.

Bertrand Caron
  • 2,525
  • 2
  • 22
  • 49
Pouria
  • 1,081
  • 9
  • 24
  • 1
    In my case it wasn't OSX but Sophos that messed up the permissions. With version 9.4.1 they fixed that bug. – Arwed Jan 22 '16 at 08:21
  • That's interesting! I have Sohpos 9.2.9 and it's not been causing problems. Although mine is not the Home version. – Pouria Jan 26 '16 at 12:41
2

I replaced the script /usr/local/bin/brew with the new version I found on github. Now everything is fine again.

The latest file, of which, can be found here:

ScriptAutomate
  • 980
  • 9
  • 17
Arwed
  • 1,755
  • 3
  • 16
  • 26
0

A little dirty but I just uninstalled homebrew and reinstalled. WARNING: This will uninstall all brew installed packages.

$ 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)"
lwelna
  • 165
  • 1
  • 3
  • 8
0

What worked for me was to run brew upgrade (NOT brew update). You might encounter some permissions issues as mentioned in some of the other answers. It will suggest some commands to fix that.

After the permission issue is fixed, running brew upgrade fixed the issue. It is apparently not an uncommon issue when updating OS - Read about it on the official Homebrew Documenation.

Backer
  • 1,094
  • 1
  • 20
  • 33