技術ブログっぽいなにか

Ruby・Railsメインでいろんなこと書きます

bundle config --global と --local の違い

別用で bundle config について調べてたときに見かけたのでめも📝

bundler.io

結論

--global は設定を ~/.bundle/config に保存する。
--local は設定を application_name/.bundle/config に保存する。

読んでみた

Executing bundle config will set that configuration to the value specified for all bundles executed as the current user. The configuration will be stored in ~/.bundle/config. If name already is set, name will be overridden and user will be warned.
Executing bundle config --global works the same as above.
Executing bundle config --local will set that configuration to the local application. The configuration will be stored in app/.bundle/config.

「--global のときは上記と同じ場所(つまり ~/.bundle/config)に保存するよ。--local のときは設定をローカルのアプリケーションの app/.bundle/config に保存するよ」

やってみた

ちょうどパーフェクト Rails の実践をやってたディレクトリがあったのでここでやってみる
アプリケーション直下の ~/.bundle を見てみるとなにもない。

🍣  ~/workspace/perfect-rails/part-1  ll  ~/.bundle/  
total 0
drwxr-xr-x  3 ichiokanatsumi  staff    96B 10  1  2016 cache

この状態で bundle config --local path vendor/bundle をやってみると .bundle/config ができて、中に設定が書いてあった

🍣  ~/workspace/perfect-rails/part-1  bundle config --local path vendor/bundle
🍣  ~/workspace/perfect-rails/part-1  less .bundle/config 
---
BUNDLE_PATH: "vendor/bundle"

続いて bundle config --global path vendor/bundle やってみた。
「あなたのアプリケーションには vendor/bundle が設定されてるよ。この設定は global の設定で上書きされるよ」ってお知らせしてくれた。 で、かつ ~/.bundle/config が生まれた

🍣  ~/workspace/perfect-rails/part-1  bundle config --global path vendor/bundle
Your application has set path to "vendor/bundle". This will override the global value you are currently setting
🍣  ~/workspace/perfect-rails/part-1  less  ~/.bundle/config   
---
BUNDLE_PATH: "vendor/bundle"

消してみる

さっきのドキュメント、もうちょい下まで読むと --delete オプションについて書かれていた。

Executing bundle config --delete will delete the configuration in both local and global sources. Not compatible with --global or --local flag.

「--delete 使うとローカルもグローバルもどっちの設定も削除するよ。これは --global と --local では互換性がないよ」

ということでやってみた。

🍣  ~/workspace/perfect-rails/part-1  bundle config --delete  path
🍣  ~/workspace/perfect-rails/part-1  less  ~/.bundle/config 
---
🍣  ~/workspace/perfect-rails/part-1  less  .bundle/config   
---
🍣  ~/workspace/perfect-rails/part-1

コマンドは一回しか実行してないけどどっちも設定消えてた。
.bundle/config のファイル自体は削除せず設定だけを削除するんですね〜

tips とか間違いあったらぜひコメントで指摘ください。