brewのエラーcannot load such file -- active_support/core_ext/object/blank

brewのエラーcannot load such file -- active_support/core_ext/object/blank

brew updaterbenv で管理しているrubyバージョンの変更などをしていたらエラーが起きた。

% brew --help
Traceback (most recent call last):
	3: from /usr/local/Homebrew/Library/Homebrew/brew.rb:23:in `<main>'
	2: from /usr/local/Homebrew/Library/Homebrew/brew.rb:23:in `require_relative'
	1: from /usr/local/Homebrew/Library/Homebrew/global.rb:12:in `<top (required)>'
/usr/local/Homebrew/Library/Homebrew/global.rb:12:in `require': cannot load such file -- active_support/core_ext/object/blank (LoadError)

brew コマンド自体が実行できないという。

rubyの現状確認

rubyのバージョンは少し古かったがパスも通っているし特に問題は無さそう。

% which ruby
/Users/me/.rbenv/bin/shims/ruby
% ruby --version
ruby 2.6.1p33 (2019-01-30 revision 66950) [x86_64-darwin18]

brewのインストール

brewのインストールコマンドを実行する

% /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

結果

==> This script will install:
/usr/local/bin/brew
/usr/local/share/doc/homebrew
/usr/local/share/man/man1/brew.1
/usr/local/share/zsh/site-functions/_brew
/usr/local/etc/bash_completion.d/brew
/usr/local/Homebrew
==> The following new directories will be created:
/usr/local/sbin
==> The Xcode Command Line Tools will be installed.

Press RETURN to continue or any other key to abort
==> /usr/bin/sudo /bin/mkdir -p /usr/local/sbin
Password:
==> /usr/bin/sudo /bin/chmod g+rwx /usr/local/sbin
==> /usr/bin/sudo /bin/chmod 755 /usr/local/share/zsh /usr/local/share/zsh/site-functions
==> /usr/bin/sudo /usr/sbin/chown me /usr/local/sbin
==> /usr/bin/sudo /usr/bin/chgrp admin /usr/local/sbin
==> Searching online for the Command Line Tools
==> /usr/bin/sudo /usr/bin/touch /tmp/.com.apple.dt.CommandLineTools.installondemand.in-progress
==> Installing Command Line Tools for Xcode-11.2
==> /usr/bin/sudo /usr/sbin/softwareupdate -i Command\ Line\ Tools\ for\ Xcode-11.2
Software Update Tool


Downloading Command Line Tools for Xcode
Downloaded Command Line Tools for Xcode
Installing Command Line Tools for Xcode
Done with Command Line Tools for Xcode
Done.
==> /usr/bin/sudo /bin/rm -f /tmp/.com.apple.dt.CommandLineTools.installondemand.in-progress
==> /usr/bin/sudo /usr/bin/xcode-select --switch /Library/Developer/CommandLineTools
==> Downloading and installing Homebrew...
From https://github.com/Homebrew/brew
 - [deleted]             (none)     -> origin/master
fatal: ambiguous argument 'origin/master': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]'
Failed during: git reset --hard origin/master

gitでエラーが出た

gitでエラーが起きるのは想定外だった。
gitはbrewでインストールしたバージョンにパスが通っていた。

% which git
/usr/local/bin/git

あたりをつける

問題が起きる前にrubyのバージョン確認をしたりrbenvをアップグレードしようとしたので、まずはrubyのバージョンを整理することにする。

rbenv

rbenvの実行は問題無かった。
2.6.3をインストールしているのに2.6.1をglobalに設定していた。

% rbenv versions
  system
  2.2.2
  2.2.9
  2.4.1
  2.5.1
  2.5.3
* 2.6.1 (set by /Users/me/.rbenv/bin/version)
  2.6.3

現時点でインストールされている最新版2.6.3をglobalに設定し、とりあえず直近で必要なgemのインストール。過去のバージョンはuninstallする。

% rbenv global 2.6.3
% rbenv rehash
% gem install bundle bundler cocoapods

% rbenv uninstall 2.2.2
rbenv: remove /Users/me/.rbenv/bin/versions/2.2.2? [yN] y
% rbenv uninstall 2.2.9
rbenv: remove /Users/me/.rbenv/bin/versions/2.2.9? [yN] y
% rbenv uninstall 2.4.1
rbenv: remove /Users/me/.rbenv/bin/versions/2.4.1? [yN] y
% rbenv uninstall 2.5.1
rbenv: remove /Users/me/.rbenv/bin/versions/2.5.1? [yN] y
% rbenv uninstall 2.5.3
rbenv: remove /Users/me/.rbenv/bin/versions/2.5.3? [yN] y
% rbenv uninstall 2.6.1
rbenv: remove /Users/me/.rbenv/bin/versions/2.6.1? [yN] y

brewの再インストール

% /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
==> This script will install:
/usr/local/bin/brew
/usr/local/share/doc/homebrew
/usr/local/share/man/man1/brew.1
/usr/local/share/zsh/site-functions/_brew
/usr/local/etc/bash_completion.d/brew
/usr/local/Homebrew

Press RETURN to continue or any other key to abort
==> Downloading and installing Homebrew...
From https://github.com/Homebrew/brew
 * [new branch]          master     -> origin/master
HEAD is now at 0ff53e6c9 Merge pull request #6665 from Homebrew/dependabot/bundler/Library/Homebrew/tins-1.22.0
Updated 2 taps (homebrew/core and homebrew/cask).
==> New Formulae
calceph                                              openjdk                                              openjdk@11                                           openjdk@12
==> Updated Formulae
mysql@5.6 ✔                                                                                                cython
==> Installation successful!

==> Homebrew has enabled anonymous aggregate formulae and cask analytics.
Read the analytics documentation (and how to opt-out) here:
  https://docs.brew.sh/Analytics

==> Homebrew is run entirely by unpaid volunteers. Please consider donating:
  https://github.com/Homebrew/brew#donations
==> Next steps:
- Run `brew help` to get started
- Further documentation:
    https://docs.brew.sh

インストール成功。

% brew help
Example usage:
  brew search [TEXT|/REGEX/]
  brew info [FORMULA...]
  brew install FORMULA...
  brew update
  brew upgrade [FORMULA...]
  brew uninstall FORMULA...
  brew list [FORMULA...]

Troubleshooting:
  brew config
  brew doctor
  brew install --verbose --debug FORMULA

Contributing:
  brew create [URL [--no-fetch]]
  brew edit [FORMULA...]

Further help:
  brew commands
  brew help [COMMAND]
  man brew
  https://docs.brew.sh

ruby-buildのアップグレード

rbenvでインストールできるrubyバージョンはruby-buildに依存する。
ruby-buildはbrewでインストールしているが brew update ではアップデートされない。 brew upgrade ruby-build コマンドが必要になる(ruby-buildは省略しても良い)

% brew upgrade ruby-build
==> Upgrading 1 outdated package:
ruby-build 20190615 -> 20191105
==> Upgrading ruby-build
==> Installing dependencies for ruby-build: openssl@1.1 and readline
==> Installing ruby-build dependency: openssl@1.1
==> Downloading https://homebrew.bintray.com/bottles/openssl@1.1-1.1.1d.catalina.bottle.tar.gz
==> Downloading from https://akamai.bintray.com/d7/d7f992ebfd78f80828051f6dc6a1a99aed405f86b0f39ea651fd0afeadd1b0f4?__gda__=exp=1573022595~hmac=1d3a901a98f6d0cb6151c4c33d35a6420a9dd0224a91c88ba73f2685ea7321ab&resp
######################################################################## 100.0%
==> Pouring openssl@1.1-1.1.1d.catalina.bottle.tar.gz
==> Caveats
A CA file has been bootstrapped using certificates from the system
keychain. To add additional certificates, place .pem files in
  /usr/local/etc/openssl@1.1/certs

and run
  /usr/local/opt/openssl@1.1/bin/c_rehash

openssl@1.1 is keg-only, which means it was not symlinked into /usr/local,
because openssl/libressl is provided by macOS so don't link an incompatible version.

If you need to have openssl@1.1 first in your PATH run:
  echo 'export PATH="/usr/local/opt/openssl@1.1/bin:$PATH"' >> ~/.zshrc

For compilers to find openssl@1.1 you may need to set:
  export LDFLAGS="-L/usr/local/opt/openssl@1.1/lib"
  export CPPFLAGS="-I/usr/local/opt/openssl@1.1/include"

For pkg-config to find openssl@1.1 you may need to set:
  export PKG_CONFIG_PATH="/usr/local/opt/openssl@1.1/lib/pkgconfig"

==> Summary
?  /usr/local/Cellar/openssl@1.1/1.1.1d: 7,983 files, 17.9MB
==> Installing ruby-build dependency: readline
==> Downloading https://homebrew.bintray.com/bottles/readline-8.0.1.catalina.bottle.tar.gz
==> Downloading from https://akamai.bintray.com/ab/ab3c966f4cae7d0f3ecc5688bb989820c3261f5ed547a08c84186ba7f53bdd9c?__gda__=exp=1573022615~hmac=f4bcdd3d610340379dee2603fe3e05d7a86c094216e4c18a936294e2b1164bba&resp
######################################################################## 100.0%
==> Pouring readline-8.0.1.catalina.bottle.tar.gz
==> Caveats
readline is keg-only, which means it was not symlinked into /usr/local,
because macOS provides the BSD libedit library, which shadows libreadline.
In order to prevent conflicts when programs look for libreadline we are
defaulting this GNU Readline installation to keg-only.

For compilers to find readline you may need to set:
  export LDFLAGS="-L/usr/local/opt/readline/lib"
  export CPPFLAGS="-I/usr/local/opt/readline/include"

For pkg-config to find readline you may need to set:
  export PKG_CONFIG_PATH="/usr/local/opt/readline/lib/pkgconfig"

==> Summary
?  /usr/local/Cellar/readline/8.0.1: 48 files, 1.5MB
==> Installing ruby-build
==> Downloading https://github.com/rbenv/ruby-build/archive/v20191105.tar.gz
==> Downloading from https://codeload.github.com/rbenv/ruby-build/tar.gz/v20191105
######################################################################## 100.0%
==> ./install.sh
?  /usr/local/Cellar/ruby-build/20191105: 461 files, 231KB, built in 9 seconds
Removing: /usr/local/Cellar/ruby-build/20190615... (448 files, 224.6KB)
==> Caveats
==> openssl@1.1
A CA file has been bootstrapped using certificates from the system
keychain. To add additional certificates, place .pem files in
  /usr/local/etc/openssl@1.1/certs

and run
  /usr/local/opt/openssl@1.1/bin/c_rehash

openssl@1.1 is keg-only, which means it was not symlinked into /usr/local,
because openssl/libressl is provided by macOS so don't link an incompatible version.

If you need to have openssl@1.1 first in your PATH run:
  echo 'export PATH="/usr/local/opt/openssl@1.1/bin:$PATH"' >> ~/.zshrc

For compilers to find openssl@1.1 you may need to set:
  export LDFLAGS="-L/usr/local/opt/openssl@1.1/lib"
  export CPPFLAGS="-I/usr/local/opt/openssl@1.1/include"

For pkg-config to find openssl@1.1 you may need to set:
  export PKG_CONFIG_PATH="/usr/local/opt/openssl@1.1/lib/pkgconfig"

==> readline
readline is keg-only, which means it was not symlinked into /usr/local,
because macOS provides the BSD libedit library, which shadows libreadline.
In order to prevent conflicts when programs look for libreadline we are
defaulting this GNU Readline installation to keg-only.

For compilers to find readline you may need to set:
  export LDFLAGS="-L/usr/local/opt/readline/lib"
  export CPPFLAGS="-I/usr/local/opt/readline/include"

For pkg-config to find readline you may need to set:
  export PKG_CONFIG_PATH="/usr/local/opt/readline/lib/pkgconfig"

upgrade成功。

rubyのバージョンを最新にする

インストール可能なrubyバージョンを確認

% rbenv install --list
(略)
2.6.0
2.6.1
2.6.2
2.6.3
2.6.4
2.6.5
2.7.0-dev
2.7.0-preview1
2.7.0-preview2
(略)

ということなので2.6.5のインストールを行う。

# インストール
% rbenv install 2.6.5
ruby-build: using openssl from homebrew
Downloading ruby-2.6.5.tar.bz2...
-> https://cache.ruby-lang.org/pub/ruby/2.6/ruby-2.6.5.tar.bz2
Installing ruby-2.6.5...
ruby-build: using readline from homebrew
Installed ruby-2.6.5 to /Users/me/.rbenv/bin/versions/2.6.5

# 2.6.5をglobalに設定
% rbenv global 2.6.5
% rbenv rehash

# 不要なバージョンを削除
% rbenv uninstall 2.6.3
rbenv: remove /Users/me/.rbenv/bin/versions/2.6.3? [yN] y

# バージョンを確認
% rbenv versions
  system
* 2.6.5 (set by /Users/me/.rbenv/bin/version)