LoginSignup
68
63

More than 3 years have passed since last update.

bundlerで非推奨になった --path --binstubs

Last updated at Posted at 2019-12-28

環境(2019/12/29時点)

ruby:2.6.5
bundler:2.1.2

bundleで--pathと--binstubsが非推奨[DEPRECATED]になったよ

railsアプリを作る際、bundle initした後にやるおまじないがあります。

$ bundle install --path vendor/bundle --binstubs=vendor/bin
  • ローカルにgemをインストールするため --pathオプションでvendor/bundleを指定
  • bundle execを打ちたくないので --binstubsオプションでvendor/binを指定

いつものように上記のコマンドを打つと、以前は出なかった以下のメッセージが出るようになりました。

[DEPRECATED] The `--path` flag is deprecated because it relies on being remembered across bundler invocations, which bundler will no longer do in future versions. Instead please use `bundle config set path 'vendor/bundle'`, and stop using this flag
[DEPRECATED] The --binstubs option will be removed in favor of `bundle binstubs`

--pathも--binstubsも非推奨[DEPRECATED]となり、今後のバージョンからremovedされる可能性があるだと…。

vendor/bundleについては以下のようなQiitaもありますが

bundle install時に--path vendor/bundleを付ける必要性は本当にあるのか、もう一度よく考えてみよう
ここではそれについては議論しませんよ。

どうすりゃいいのさ[vendor/bundle]

メッセージに書いてある通りに

bundle config set path 'vendor/bundle'

を一回やっとけばOKです。
bundle configコマンドで確認できます。

$ bundle config
path
Set for the current user (/Users/hoge/.bundle/config): "vendor/bundle"

これをやっとけば、bundle insallで毎回vendor/bundleにインストールされます。

どうすりゃいいのさ[binstubs=vendor/bin]

bundle binstubs docs
bundle installの前に以下のコマンドでvendor/bin以下にstubさせます。
"bundle binstubs needs at least one gem to run."と出ますが気にしない。

$ bundle binstubs --path=vendor/bin
`bundle binstubs` needs at least one gem to run.

アプリ直下に.bundle/configファイルが作成され、BUNDLE_BINのパスがここに書かれます。

.bundle/config
---
BUNDLE_BIN: "vendor/bin"

bundle configで確認。

$ bundle config
Settings are listed in order of priority. The top value will be used.
path
Set for the current user (/Users/hoge/.bundle/config): "vendor/bundle"
bin
Set for your local app (/Users/hoge/fuga/hege/.bundle/config): "vendor/bin"

ここまでやって初めてbundle installです。

$ bundle install

binstubを設定したので、vendor/binにもrailsやらrakeができます。
これはvendor/bundle/ruby/2.6.0/binにあるものとは違います。
この状態で、bundle execとはおさらばです。

晴れてrails newできます。

$ rails new .

やったね!

まとめ(順番)

1.bundle config set path 'vendor/bundle'
2.bundle init
3.bundle binstubs --path=vendor/bin
4.bundle install
5.rails new .

68
63
0

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
68
63