はじめに
時間が空いた時に忘れてしまいがちなのでここにメモ兼この記事を見ていただいた方の解決策の一つになれれば嬉しいです。
環境
- mac
- Ruby 2.5.1
- Rails 6.0.2.2
bundle updateをしたらrailsコマンドが使えない…
# bundle updateは通る
$ bundle update kaminari
・
・
・
Bundle updated!
railsコマンドを打つと…
$ rails -v
Beginning in Rails 4, Rails ships with a `rails` binstub at ./bin/rails that
should be used instead of the Bundler-generated `rails` binstub.
If you are seeing this message, your binstub at ./bin/rails was generated by
Bundler instead of Rails.
# `rails`binstubを再生成する必要があるかもみたいなことを言っている
You might need to regenerate your `rails` binstub locally and add it to source
control:
rails app:update:bin # Bear in mind this generates other binstubs
# too that you may or may not want (like yarn)
# binstubが既にあるならばbundle installにbinstubオプションを付けて実行
If you already have Rails binstubs in source control, you might be
inadvertently overwriting them during deployment by using bundle install
with the --binstubs option.
If your application was created prior to Rails 4, here's how to upgrade:
bundle config --delete bin # Turn off Bundler's stub generator
rails app:update:bin # Use the new Rails executables
git add bin # Add bin/ to source control
You may need to remove bin/ from your .gitignore as well.
When you install a gem whose executable you want to use in your app,
generate it and add it to source control:
bundle binstubs some-gem-name
git add bin/new-executable
rails app:update:binを実行
railsコマンドを打った時と同様の上記のメッセージが表示された後に追加で表示される
$ rails app:update:bin
exist bin
conflict bin/rails
# 下のことを聞かれるのでEnterを押す
Overwrite /railsアプリのディレクトリ/bin/rails? (enter "h" for help) [Ynaqdhm]
force bin/rails
conflict bin/rake
# 下のことを聞かれるのでEnterを押す
Overwrite /railsアプリのディレクトリ/bin/rake? (enter "h" for help) [Ynaqdhm]
force bin/rake
identical bin/setup
identical bin/yarn
# railsコマンドを打つ
$ rails -v
Rails 6.0.2.2
無事に表示されました。
bundle installでも同様
bundle installを行っても、bundle updateでgemの指定をしなくても同じようになりました。
なぜこうなったのか考える
bundle updateやbundle installによって、実行ファイルとgemとで差異が起きたと思われる。
そして、binstubを新しくすることで解消になったと考えるが、これより先のことはまだわかっていません。
もう一度bundle updateなどを行うと再度エラーが出てくる
解決はできるものの、gemに変更をするたびに出てこられるのは手間ですね。
現在の私だとまだまだわからないことが多く、本質的な解決に至っていないので、ゆくゆくはbinstubやrailsがやってくれていることも理解していきたいです。
まとめ
この記事で問題解決が完結とまでは導き出せませんでしたが、いつか戻ってきた時に解決できるように力をつけたいですね。
また、解決方法がありましたらコメントを残していただけると嬉しい限りです。