bundlerについて疑問に思ったことを調べた
bundlerについていくつか調べたことについてのまとめ。ただし中途半端。間違ってたら教えてください><
Bundler: The best way to manage Ruby applications
コマンド一覧
Tasks: bundle check # Checks if the dependencies listed in Gemfile are satisfied by currently installed gems bundle console [GROUP] # Opens an IRB session with the bundle pre-loaded bundle exec # Run the command in context of the bundle bundle help [TASK] # Describe available tasks or one specific task bundle init # Generates a Gemfile into the current working directory bundle install # Install the current environment to the system bundle lock # Locks the bundle to the current set of dependencies, including all child dependencies. bundle open GEM # Opens the source directory of the given bundled gem bundle package # Locks and then caches all of the gems into vendor/cache bundle show [GEM] # Shows all gems that are part of the bundle, or the path to a given gem bundle unlock # Unlock the bundle. This allows gem versions to be changed. bundle version # Prints the bundler's version information
bundle install
bundle installしたときの格納場所は
- BUNDLE_PATH
- ~/.bundle
の順番。
bundle install path
のようにすると、.bundle/config の中に BUNDLE_PATH が設定される。
system 的なところに格納されていれば、いちいち ~/.bundle 配下にコピーしてきたりはしない。たぶんいろんなパスを順番で見ていって最初に見つけたgemを使うのだと思う。
デフォルトではユーザのホームディレクトリ配下の.bundlerにインストールされるので、例えば
sudo su bundle console
などとすると gem が見つからなくてエラーになる。
sudo bundle console
だと実行できる(たぶんsudo元のユーザを見てる)。なぜか nginx ユーザで passenger 使うと大丈夫だったりする?このへんよくわかってないけど、サーバで使う時には基本的には
bundle install vendor/bundler
などして、ホームディレクトリ配下にインストールしないように工夫する必要がありそう。
ローカルで作業してサーバにアップロードしたいとき
bundle install --disable-shared-gems vendor/bundler
とする。 --disable-shared-gems オプションを使うと、system でインストールしたgemもBUNDLE_PATHにインストールする。
バージョン固定したいとき
bundler lock
としてバージョンを固定する。 Gemfile.lock にインストールしたgemのバージョン情報が入る。
bundle package
bundle package
とすると、 vendor/cacheに gem が入る。ここにある gem はリモートサーバにあるgemのキャッシュ的な使われ方をするみたい。これをうまく使うと gemcutterとかの他のサーバに接続しないでbundle installできる(未確認)。