18
12

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

【Rails】bundle install したときに vender/bundle にインストールされるのをデフォルトに戻す

Last updated at Posted at 2020-02-20

はじめに

Railsで開発している時、エラーを解決しようとガチャガチャやった後、bundle installしたらなぜかプロジェクト下の vender/bundle に gem がインストールされるようになってしまいました。とりあえず前の状態に戻したいと思い、原因と解決法を探りました。

bundle install --path vender/bundle

調べてみると、むしろbundle install --path vender/bundleを推奨する記事が散見されましたが、下記の記事のようにこの慣習に疑問を呈している記事もありました。

bundle install時に--path vendor/bundleを付ける必要性は本当にあるのか、もう一度よく考えてみよう

デフォルトに戻す

ググると以下のような方法をすぐに見つけました。

Bundlerがどこからgemを探すかは、プロジェクトルートの下の.bundle/configに設定ファイルがあります。これを消すことで、新たな場所にbundle installできるようになります。

しかし、私の場合この方法では症状解決しませんでした。
そこで、もう一度bundle installしプロジェクト下に作成された .bundle/config ファイルを確認しました。

.bundle/config
---
BUNDLE_WITHOUT: "production"

…特にpathオプションに関連するものはありませんでした。

そこでbundler configでどのようなオプションが設定されているかを確認しました。

$ bundler config
Settings are listed in order of priority. The top value will be used.
without
Settings are listed in order of priority. The top value will be used.
path
Set for the current user (/Users/punkshiraishi/.bundle/config): "vendor/bundle"

これで path オプションが /Users/[ユーザ名]/.bundle/config で設定されていることが分かったので開いてみると

/Users/[ユーザ名]/.bundle/config
---
BUNDLE_WITHOUT: "production"
BUNDLE_PATH: vendor/bundle

ありました!
このBUNDLE_PATH: vendor/bundleを削除し、bundle installすることで、使用中の Ruby 直下に gem がインストールされるようになりました!

更に調べてみると bundler のオプションは

  • Railsプロジェクト下の .bundle/config
  • 環境変数
  • ユーザのホームディレクトリ下の .bundle/config

の3つにあるということが分かりました。プロジェクト直下の .bundle/config を削除しても設定が戻らないという方は上記も調べてみると良いかもしれません。

参考

18
12
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
18
12

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?