在macOS 11.0 Beta版 中 brew运行任何命令都会报错,原因是 brew 只支持正式发行版。
错误堆栈
~ brew listTraceback (most recent call last): 11: from /usr/local/Homebrew/Library/Homebrew/brew.rb:23:in `<main>' 10: from /usr/local/Homebrew/Library/Homebrew/brew.rb:23:in `require_relative' 9: from /usr/local/Homebrew/Library/Homebrew/global.rb:29:in `<top (required)>' 8: from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require' 7: from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require' 6: from /usr/local/Homebrew/Library/Homebrew/os.rb:3:in `<top (required)>' 5: from /usr/local/Homebrew/Library/Homebrew/os.rb:21:in `<module:OS>' 4: from /usr/local/Homebrew/Library/Homebrew/os/mac.rb:58:in `prerelease?' 3: from /usr/local/Homebrew/Library/Homebrew/os/mac.rb:24:in `version' 2: from /usr/local/Homebrew/Library/Homebrew/os/mac.rb:24:in `new' 1: from /usr/local/Homebrew/Library/Homebrew/os/mac/version.rb:26:in `initialize' /usr/local/Homebrew/Library/Homebrew/version.rb:368:in `initialize': Version value must be a string; got a NilClass () (TypeError)
解决办法
从错误中可以看得出来 是version.rb 这个文件的368行报错,我们可以直接给他个写死的版本 即可,让他认为macOS是正式发行版
修改后代码:
def initialize(val) #raise TypeError, "Version value must be a string; got a #{val.class} (#{val})" unless val.respond_to?(:to_str) @version = '10.14.1' end
把抛出异常的语句注释掉,然后 version 指定为 10.14.1
再次运行就不会报错了。
记得最好不要更新brew,不然代码可能会被覆盖掉。下次还得改一遍。