【Ruby on Rails】 bundler1.11.2に更新したら?rails g migration, rails cなどができなくなって困った
rails g migrationとかrails cの突然の死
bundle install
した際に「bundler古いよ」と言われたので、その後rbenv exec gem update bundler
で1.11.2
に更新しました。
すると今度は(bundle exec)rails g migration
やrails c
でエラーが出るようになりました(なぜかrails s
は大丈夫ですが)
(でも結局bundlerを更新したせいなのかどうかはわかりません)
/Users/noriyo_tcp/.rbenv/versions/2.2.3/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require': cannot load such file -- bundler/setup (LoadError) from /Users/noriyo_tcp/.rbenv/versions/2.2.3/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require' from /Users/noriyo_tcp/workspace/feel/vendor/bundle/ruby/2.2.0/gems/spring-1.6.0/lib/spring/commands.rb:33:in `<module:Spring>' from /Users/noriyo_tcp/workspace/feel/vendor/bundle/ruby/2.2.0/gems/spring-1.6.0/lib/spring/commands.rb:4:in `<top (required)>' from /Users/noriyo_tcp/.rbenv/versions/2.2.3/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require' from /Users/noriyo_tcp/.rbenv/versions/2.2.3/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require' from /Users/noriyo_tcp/workspace/feel/vendor/bundle/ruby/2.2.0/gems/spring-1.6.0/lib/spring/application.rb:77:in `preload' from /Users/noriyo_tcp/workspace/feel/vendor/bundle/ruby/2.2.0/gems/spring-1.6.0/lib/spring/application.rb:143:in `serve' from /Users/noriyo_tcp/workspace/feel/vendor/bundle/ruby/2.2.0/gems/spring-1.6.0/lib/spring/application.rb:131:in `block in run' from /Users/noriyo_tcp/workspace/feel/vendor/bundle/ruby/2.2.0/gems/spring-1.6.0/lib/spring/application.rb:125:in `loop' from /Users/noriyo_tcp/workspace/feel/vendor/bundle/ruby/2.2.0/gems/spring-1.6.0/lib/spring/application.rb:125:in `run' from /Users/noriyo_tcp/workspace/feel/vendor/bundle/ruby/2.2.0/gems/spring-1.6.0/lib/spring/application/boot.rb:18:in `<top (required)>' from /Users/noriyo_tcp/.rbenv/versions/2.2.3/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require' from /Users/noriyo_tcp/.rbenv/versions/2.2.3/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require' from -e:1:in `<main>'
ググっても「bundler入れろ」的な記事しか見つからない。よく見るとSpring関係で怒れらているのかなあとは思うのですが・・・。
Spring止めてみる、というのも試したのですけど、ダメでした。
【Ruby On Rails】 「rails generate」が動かない | approad
railsのコマンドが動かない時はspringを(stop|kill)してみよう - Qiita
結論:1.10.6を使う。
まず、使えるバージョンを調べます。
初心者は覚えておきたいRubygemsのコマンドまとめ - Qiita
$ rbenv exec gem query -ra -n "^bundler$" *** REMOTE GEMS *** bundler (1.11.2, 1.11.1, 1.11.0, 1.10.6, 1.10.5, 1.10.4, 1.10.3, 1.10.2, 1.10.1, 1.10.0, ...)(長いので割愛)
1.10.6のインストール
$ rbenv exec gem install bundler -v 1.10.6 Fetching: bundler-1.10.6.gem (100%) Successfully installed bundler-1.10.6 Parsing documentation for bundler-1.10.6 Installing ri documentation for bundler-1.10.6 Done installing documentation for bundler after 6 seconds 1 gem installed
これで1.11.2と両方入ったわけですが、こんな風にバージョン指定できます。
$ bundle _1.10.6_ -v Bundler version 1.10.6 $ bundle -v Bundler version 1.11.2
version指定して実行してみます。その前にSpringは止めておく。
$ bundle _1.10.6_ exec rails c Running via Spring preloader in process 11983 Loading development environment (Rails 4.2.4) Frame number: 0/20 [1] pry(main)>
これでコンソールに入ることができています。
問題点?
- Gemfile.lockで指定されているバージョンと食い違いが起きる
- 下の記事で紹介されているようにエイリアス作るのがめんどい(いっその事古いバージョンでやり続ける?)
その後に起きた事
そこでまた普通に、つまり最新のバージョンで実行してみます。
$ bundle -v Bundler version 1.11.2 $ bundle exec rails c Running via Spring preloader in process 17072 Loading development environment (Rails 4.2.4) Frame number: 0/20 [1] pry(main)>
動いとるやんけ!! 一度古いバージョンで実行してみた事が良かったのかなあ? 結局分からずじまいです。
バージョン1.11.0以上で問題がある?みたいですけど解決してるのどうかは私の英語力の低さゆえにわかりません・・・。
Spring is broken with bundler >= 1.11.0 · Issue #456 · rails/spring · GitHub
Add bundler Dependency to gemspec by sonalkr132 · Pull Request #453 · rails/spring · GitHub
追記(2/22)
spring v.1.6.3にて問題は解消された模様。
Comparing v1.6.2...v1.6.3 · rails/spring · GitHub
qiita.com (上記記事の追記を参照のこと)
実際に動かしてみたら無事できました。よかったー。