0

I updated my MacBook Pro to Monterey (version 12.6.4).

Now when I enter any brew command on the command line, I get an exception:

/usr/local/Homebrew/Library/Homebrew/version.rb:366:in `initialize': Version value must be a string; got a NilClass () (TypeError)
from /usr/local/Homebrew/Library/Homebrew/os/mac/version.rb:23:in `initialize'
from /usr/local/Homebrew/Library/Homebrew/os/mac.rb:18:in `new'
from /usr/local/Homebrew/Library/Homebrew/os/mac.rb:18:in `version'
from /usr/local/Homebrew/Library/Homebrew/os/mac.rb:52:in `prerelease?'
from /usr/local/Homebrew/Library/Homebrew/os.rb:19:in `<module:OS>'
from /usr/local/Homebrew/Library/Homebrew/os.rb:1:in `<top (required)>'
from /usr/local/Homebrew/Library/Homebrew/vendor/portable-ruby/2.3.7/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from /usr/local/Homebrew/Library/Homebrew/vendor/portable-ruby/2.3.7/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from /usr/local/Homebrew/Library/Homebrew/global.rb:26:in `<top (required)>'
from /usr/local/Homebrew/Library/Homebrew/brew.rb:21:in `require_relative'
from /usr/local/Homebrew/Library/Homebrew/brew.rb:21:in `<main>'

My ruby --version says ruby 2.6.10p210 (2022-04-12 revision 67958) [universal.x86_64-darwin21]

I also tried the brew command by setting a Ruby 2.4.2 in front of the PATH search order, but same effect.

Digging into the code (os.rb), I found the definition of the constant

::OS_VERSION = ENV["HOMEBREW_OS_VERSION"]

and I don't have defined this environment variable, neither do I have defined HOMEBREW_OSX_VERSION. I think this could explain the NilClass exception, but I am not aware that I ever had this environment variable, and brew worked fine before.

Any idea of what is going on?

UPDATE: I also tried the suggestion on the homebrew page, i.e. doing a git clean -f in /usr/local/Homebrew/Library/Contributions/examples, but there is no Contributions directory, and a clean in the Homebrew base directory did not help either.

1 Answer 1

2

Not sure if it helps, but my experience with Homebrew Ruby-version problems after macOS updates is that this has usually solved them:

cd $(brew --repo)
git pull origin master

I.e. in the Homebrew base directory, completely reload Homebrew.

2
  • This worked indeed. Of course I had to do this in a shell with admin privileges, otherwise git pull would not have been possible. Apr 16, 2023 at 12:19
  • Same issue. This worked perfectly.
    – user766353
    Jun 19, 2023 at 0:29

You must log in to answer this question.

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