LoginSignup
170
123

More than 3 years have passed since last update.

bundle execって必要なの?

Last updated at Posted at 2020-02-11

rails sって書いても、bundle exec rails sって書いても同じ動きをするように見えるんですが、何が違うのでしょうか。気になったので調べてみました。

結論

  • bundle execをつけないと、Gemfile.lockに基づかずにgemのバージョンが決定される
  • bundle execをつけると、Gemfile.lockに書かれているバージョンのgemが動く
  • bin/rspecのように書くと、springの恩恵を受けて動作が早くなる
  • railsコマンドだけはbinを省略してもbin/railsと解釈される

だから

  • railsコマンドは何も付けずに実行
  • binディレクトリにファイルが存在するコマンドはbin/◯◯
  • それ以外のコマンドはbundle exec ◯◯
    • vscode remote container等でコンテナ内で開発してる場合はbundle exec不要

そもそもBundlerとは

  • プロジェクト内で使うGemのパッケージ管理ツール。Gemをプロジェクト単位で管理することができる。
  • rbenv(rubyのバージョンをプロジェクト単位で管理するツール)のGem版
  • bundle installコマンドを叩くと、Gemfileに記載されたGemをインストールする

bundle installした時のGemの保存先

rbenvを使っている場合

$ gem which byebug
/Users/***/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/byebug-11.0.1/lib/byebug.rb

参考

170
123
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
170
123