RailsのRubyバージョンを2.7.0から2.7.1に上げる
いつものようにRailsのRubyバージョンを上げていこうかと思います。
まずはruby-buildの最新化します。
$ brew upgrade ruby-build
rubyをrbenvで管理しているのでrbenvで2.7.1をビルドします。
$ rbenv install 2.7.1
Rails root の.ruby-version を 2.7.1 に変更
$ ruby -v ruby 2.7.1p83 (2020-03-31 revision a0c7c23c9c) [x86_64-darwin18]
$ bundle --version Bundler version 2.1.4
Gemfileのrubyのバージョンを変更
ruby '2.7.1'
.ruby-versionとGemfileのバージョンをあわせてbundle installします。
$ bundle install
rails c を起動するとエラーが表示されました。
Traceback (most recent call last): 15: from bin/rails:3:in `<main>' 14: from bin/rails:3:in `require_relative' 13: from /rails_project/config/boot.rb:4:in `<top (required)>' 12: from /rails_project/config/boot.rb:4:in `require' 11: from /rails_project/vendor/bundle/ruby/2.7.0/gems/bootsnap-1.4.6/lib/bootsnap/setup.rb:2:in `<top (required)>' 10: from /rails_project/vendor/bundle/ruby/2.7.0/gems/bootsnap-1.4.6/lib/bootsnap/setup.rb:2:in `require_relative' 9: from /rails_project/vendor/bundle/ruby/2.7.0/gems/bootsnap-1.4.6/lib/bootsnap.rb:4:in `<top (required)>' 8: from /rails_project/vendor/bundle/ruby/2.7.0/gems/bootsnap-1.4.6/lib/bootsnap.rb:4:in `require_relative' 7: from /rails_project/vendor/bundle/ruby/2.7.0/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache.rb:74:in `<top (required)>' 6: from /rails_project/vendor/bundle/ruby/2.7.0/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache.rb:74:in `require_relative' 5: from /rails_project/vendor/bundle/ruby/2.7.0/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/store.rb:4:in `<top (required)>' 4: from /rails_project/vendor/bundle/ruby/2.7.0/gems/bootsnap-1.4.6/lib/bootsnap/explicit_require.rb:41:in `with_gems' 3: from /rails_project/vendor/bundle/ruby/2.7.0/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/store.rb:4:in `block in <top (required)>' 2: from /rails_project/vendor/bundle/ruby/2.7.0/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/store.rb:4:in `require' 1: from /rails_project/vendor/bundle/ruby/2.7.0/gems/msgpack-1.3.3/lib/msgpack.rb:9:in `<top (required)>' /rails_project/vendor/bundle/ruby/2.7.0/gems/msgpack-1.3.3/lib/msgpack.rb:9:in `require': cannot load such file -- msgpack/2.7/msgpack (LoadError) 16: from bin/rails:3:in `<main>' 15: from bin/rails:3:in `require_relative' 14: from /rails_project/config/boot.rb:4:in `<top (required)>' 13: from /rails_project/config/boot.rb:4:in `require' 12: from /rails_project/vendor/bundle/ruby/2.7.0/gems/bootsnap-1.4.6/lib/bootsnap/setup.rb:2:in `<top (required)>' 11: from /rails_project/vendor/bundle/ruby/2.7.0/gems/bootsnap-1.4.6/lib/bootsnap/setup.rb:2:in `require_relative' 10: from /rails_project/vendor/bundle/ruby/2.7.0/gems/bootsnap-1.4.6/lib/bootsnap.rb:4:in `<top (required)>' 9: from /rails_project/vendor/bundle/ruby/2.7.0/gems/bootsnap-1.4.6/lib/bootsnap.rb:4:in `require_relative' 8: from /rails_project/vendor/bundle/ruby/2.7.0/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache.rb:74:in `<top (required)>' 7: from /rails_project/vendor/bundle/ruby/2.7.0/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache.rb:74:in `require_relative' 6: from /rails_project/vendor/bundle/ruby/2.7.0/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/store.rb:4:in `<top (required)>' 5: from /rails_project/vendor/bundle/ruby/2.7.0/gems/bootsnap-1.4.6/lib/bootsnap/explicit_require.rb:41:in `with_gems' 4: from /rails_project/vendor/bundle/ruby/2.7.0/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/store.rb:4:in `block in <top (required)>' 3: from /rails_project/vendor/bundle/ruby/2.7.0/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/store.rb:4:in `require' 2: from /rails_project/vendor/bundle/ruby/2.7.0/gems/msgpack-1.3.3/lib/msgpack.rb:8:in `<top (required)>' 1: from /rails_project/vendor/bundle/ruby/2.7.0/gems/msgpack-1.3.3/lib/msgpack.rb:11:in `rescue in <top (required)>' /rails_project/vendor/bundle/ruby/2.7.0/gems/msgpack-1.3.3/lib/msgpack.rb:11:in `require': incompatible library version - /rails_project/vendor/bundle/ruby/2.7.0/gems/msgpack-1.3.3/lib/msgpack/msgpack.bundle (LoadError) 16: from bin/rails:3:in `<main>' 15: from bin/rails:3:in `require_relative' 14: from /rails_project/config/boot.rb:4:in `<top (required)>' 13: from /rails_project/config/boot.rb:4:in `require' 12: from /rails_project/vendor/bundle/ruby/2.7.0/gems/bootsnap-1.4.6/lib/bootsnap/setup.rb:2:in `<top (required)>' 11: from /rails_project/vendor/bundle/ruby/2.7.0/gems/bootsnap-1.4.6/lib/bootsnap/setup.rb:2:in `require_relative' 10: from /rails_project/vendor/bundle/ruby/2.7.0/gems/bootsnap-1.4.6/lib/bootsnap.rb:4:in `<top (required)>' 9: from /rails_project/vendor/bundle/ruby/2.7.0/gems/bootsnap-1.4.6/lib/bootsnap.rb:4:in `require_relative' 8: from /rails_project/vendor/bundle/ruby/2.7.0/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache.rb:74:in `<top (required)>' 7: from /rails_project/vendor/bundle/ruby/2.7.0/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache.rb:74:in `require_relative' 6: from /rails_project/vendor/bundle/ruby/2.7.0/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/store.rb:4:in `<top (required)>' 5: from /rails_project/vendor/bundle/ruby/2.7.0/gems/bootsnap-1.4.6/lib/bootsnap/explicit_require.rb:40:in `with_gems' 4: from /rails_project/vendor/bundle/ruby/2.7.0/gems/bootsnap-1.4.6/lib/bootsnap/explicit_require.rb:44:in `rescue in with_gems' 3: from /rails_project/vendor/bundle/ruby/2.7.0/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/store.rb:4:in `block in <top (required)>' 2: from /rails_project/vendor/bundle/ruby/2.7.0/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/store.rb:4:in `require' 1: from /rails_project/vendor/bundle/ruby/2.7.0/gems/msgpack-1.3.3/lib/msgpack.rb:9:in `<top (required)>' /rails_project/vendor/bundle/ruby/2.7.0/gems/msgpack-1.3.3/lib/msgpack.rb:9:in `require': cannot load such file -- msgpack/2.7/msgpack (LoadError) 17: from bin/rails:3:in `<main>' 16: from bin/rails:3:in `require_relative' 15: from /rails_project/config/boot.rb:4:in `<top (required)>' 14: from /rails_project/config/boot.rb:4:in `require' 13: from /rails_project/vendor/bundle/ruby/2.7.0/gems/bootsnap-1.4.6/lib/bootsnap/setup.rb:2:in `<top (required)>' 12: from /rails_project/vendor/bundle/ruby/2.7.0/gems/bootsnap-1.4.6/lib/bootsnap/setup.rb:2:in `require_relative' 11: from /rails_project/vendor/bundle/ruby/2.7.0/gems/bootsnap-1.4.6/lib/bootsnap.rb:4:in `<top (required)>' 10: from /rails_project/vendor/bundle/ruby/2.7.0/gems/bootsnap-1.4.6/lib/bootsnap.rb:4:in `require_relative' 9: from /rails_project/vendor/bundle/ruby/2.7.0/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache.rb:74:in `<top (required)>' 8: from /rails_project/vendor/bundle/ruby/2.7.0/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache.rb:74:in `require_relative' 7: from /rails_project/vendor/bundle/ruby/2.7.0/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/store.rb:4:in `<top (required)>' 6: from /rails_project/vendor/bundle/ruby/2.7.0/gems/bootsnap-1.4.6/lib/bootsnap/explicit_require.rb:40:in `with_gems' 5: from /rails_project/vendor/bundle/ruby/2.7.0/gems/bootsnap-1.4.6/lib/bootsnap/explicit_require.rb:44:in `rescue in with_gems' 4: from /rails_project/vendor/bundle/ruby/2.7.0/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/store.rb:4:in `block in <top (required)>' 3: from /rails_project/vendor/bundle/ruby/2.7.0/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/store.rb:4:in `require' 2: from /rails_project/vendor/bundle/ruby/2.7.0/gems/msgpack-1.3.3/lib/msgpack.rb:8:in `<top (required)>' 1: from /rails_project/vendor/bundle/ruby/2.7.0/gems/msgpack-1.3.3/lib/msgpack.rb:11:in `rescue in <top (required)>' /rails_project/vendor/bundle/ruby/2.7.0/gems/msgpack-1.3.3/lib/msgpack.rb:11:in `require': incompatible library version - /rails_project/vendor/bundle/ruby/2.7.0/gems/msgpack-1.3.3/lib/msgpack/msgpack.bundle (LoadError)
msgpackの参照してるライブラリで参照エラーになってしまうようです。
私の場合はbundle install の際に path を vendor/bundle に設定しているので、
vendor/bundle/ruby/2.7.0 配下を削除して bundle install しなおします。
今回の2.7.1の場合, patchバージョン変更のため2.7.0のディレクトリがそのまま使われるようです。
Dockerなどでvendor配下を共有している場合も同様の事象に遭遇する可能性があるので
一旦削除して再インストールすると良いかもしれなれないです。
bundle upgrade の helpをみてみると options --ruby の項目があり
--ruby Update the locked version of Ruby to the current version of Ruby.
と記載されていたので、 試してみたのですが 同様のエラーになって動作しなかったので使い方が違いそうです。
テストがある方は rails testなどでテストして動作確認してください。
$ rails test