LoginSignup
112
102

More than 5 years have passed since last update.

Bundlerでビルドオプションを指定する

Last updated at Posted at 2015-08-16

gemコマンドでインストール時に

$ gem install nokogiri -- --use-system-libraries

というようにオプションを指定するとき、bundlerではどうやるのってなったので調べてみました

やり方

bundle installをする前に

$ bundle config build.nokogiri --use-system-libraries

というコマンドを叩くと、~/.bundle/config(プロジェクトルート下ではなくホームディレクトリであることに注意)という設定ファイルに以下の様な設定が追記されます。

~/.bundle/config
---
BUNDLE_BUILD__NOKOGIRI: "--use-system-libraries"

次回以降bundle installするときはそのオプションが適応されるようになります。

また、--localオプションをつけることで、ホームディレクトリ下ではなくプロジェクト単位の設定ファイルに設定を付与することができるようです。(@msfukuiさん多謝!)

$ bundle config --local build.nokogiri --use-system-libraries
You are replacing the current local value of build.nokogiri, which is currently nil

Bundlerの設定の読み込み先と設定項目の確認

Bundlerの設定は

  1. Railsルート下の .bundle/config
  2. 環境変数
  3. ユーザのホームディレクトリ下の .bundle/config

の3箇所から読み込まれ、この順番に設定を探します。

設定したBundlerの項目は、bundle configで確認することができます。

$ bundle config
Settings are listed in order of priority. The top value will be used.
build.nokogiri
Set for the current user (/home/vagrant/.bundle/config): "--use-system-libraries"

path
Set for your local app (/var/www/public/sample_app/.bundle/config): "vendor/bundle"

disable_shared_gems
Set for your local app (/var/www/public/sample_app/.bundle/config): "1"

どこの設定ファイルに書いてあるのか、ユーザーに紐付いているのかローカルアプリに紐付いているのかも書いていますね。
bundle install --path vendor/bundleとしたときの--pathの情報も書いてあるのがわかります。

また、RailsコンソールからもBundler.settings["設定項目"]で確認できるようです。

$ rails c
> Bundler.settings["build.nokogiri"]
=> "--use-system-libraries"

参考

bundle install で、gem install のオプションを指定する方法
bundle config

112
102
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
112
102