brew报错:`initialize': Version value must be a string; got a NilClass () (TypeError)

2020-08-17 发表在 工具 719

在macOS 11.0 Beta版 中 brew运行任何命令都会报错,原因是 brew 只支持正式发行版。

  • 错误堆栈
 ~ brew list
Traceback (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,不然代码可能会被覆盖掉。下次还得改一遍。

作者:贝塔博客
本站使用「署名 4.0 国际」创作共享协议,转载请在文章明显位置注明作者及出处。
评论
登录以后才可以发布评论哦, 点击登录 发布评论
评论列表 0人参与,0条评论
暂时还没有人评论,快来一条神回复吧!