高木のブログ

【Mac】rbenvでRubyのバージョンを最新に上げる時のメモ

2021/05/22

Rubyのバージョンを上げるのに手こずったのでメモしておく
Homebrewでrbenvを入れた前提

バージョン

作業前のバージョン

$ brew --version
Homebrew 3.1.1
Homebrew/homebrew-core (git revision d7d84be345; last commit 2021-04-14)

$ rbenv --version
rbenv 1.1.2

$ ruby-build --version
ruby-build 20210510

手順

$ brew update
$ brew upgrade rbenv ruby-build
$ rbenv install --list
2.6.7
2.7.3
3.0.1
jruby-9.2.17.0
mruby-3.0.0
rbx-5.0
truffleruby-21.1.0
truffleruby+graalvm-21.1.0

Only latest stable releases for each Ruby implementation are shown.
Use 'rbenv install --list-all / -L' to show all local versions.
$ rbenv install 2.7.3
$ rbenv global 2.7.3
$ ruby --version
ruby 2.7.3p183 (2021-04-05 revision 6847ee089d) [x86_64-darwin19]

バージョン

バージョン情報も一応載せておく

作業前のバージョン

$ brew --version
Homebrew 3.1.1
Homebrew/homebrew-core (git revision d7d84be345; last commit 2021-04-14)

$ rbenv --version
rbenv 1.1.2

$ ruby-build --version
ruby-build 20210510

作業後のバージョン

$ brew --version
Homebrew 3.1.8
Homebrew/homebrew-core (git revision 4a2cac5078c; last commit 2021-05-21)

$ rbenv --version
rbenv 1.1.2

$ ruby-build --version
ruby-build 20210510

ハマったところ

問題

brew updateでエラーメッセージがでた

$ brew update
Error:
  homebrew-core is a shallow clone.
To `brew update`, first run:
  git -C /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core fetch --unshallow
This command may take a few minutes to run due to the large size of the repository.
This restriction has been made on GitHub's request because updating shallow
clones is an extremely expensive operation due to the tree layout and traffic of
Homebrew/homebrew-core and Homebrew/homebrew-cask. We don't do this for you
automatically to avoid repeatedly performing an expensive unshallow operation in
CI systems (which should instead be fixed to not use shallow clones). Sorry for
the inconvenience!

解決方法

エラーメッセージにも書いてある以下のコマンドを打つ

$ git -C /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core fetch --unshallow
$ git -C /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core fetch --unshallow
remote: Enumerating objects: 326749, done.
remote: Counting objects: 100% (326728/326728), done.
remote: Compressing objects: 100% (139829/139829), done.
remote: Total 319120 (delta 182447), reused 313109 (delta 176494), pack-reused 0
Receiving objects: 100% (319120/319120), 84.07 MiB | 21.33 MiB/s, done.
Resolving deltas: 100% (182447/182447), completed with 4657 local objects.
From https://github.com/Homebrew/homebrew-core
   d7d84be3451..4a2cac5078c master     -> origin/master

詳細は参考の2つ目のリンク

参考


Written by ytkg, Twitter, GitHub

Pixela