LoginSignup
22
17

More than 3 years have passed since last update.

Could not find!! railsコマンドを打ってrakeが見つからないとエラーが出た時の対処方法

Last updated at Posted at 2019-01-17

Could not findって言われた

scaffoldでモデルを作成しようと以下のコマンドを打ったら

$ rails generate scaffold model column:data-type

以下のようなエラーが吐かれて実行されなかった。

Could not find rake-12.3.2 in any of the sources (Bundler::GemNotFound)

環境

Rails5.2
Bundler version 1.17.1

なぜこのようなことが起こるのか

それは、bundleのpathがおかしいから。いわゆる、configuration errorの一つってことですね。なぜpathがおかしくなるかはいじくりまわしすぎが主な原因だと思うので、これといって断定できないです。

解決策

bundleのパスを指定して、そこにGemfileで書いたgemが落ちてくるようにすれば良い。

$ bundle install --path vendor/cache

これでこのオプションで指定したディレクトリの直下にgemがインストールされるようになる。
設定がちゃんとされているかを下記のコマンドを使って確認してみると、以下のような標準出力がなされて、pathがvendor/pathに設定されているのがわかると思います。

多分、Could not found rakeが出ている時にbundle configってやったら変なとこにパスが作られているのではないかと思われる・・・

$ bundle config

Settings are listed in order of priority. The top value will be used.
path
Set for your local app (/bundle/config): "vendor/cache"
Set via BUNDLE_PATH: "/bundle"

silence_root_warning
Set via BUNDLE_SILENCE_ROOT_WARNING: true

app_config
Set via BUNDLE_APP_CONFIG: "/bundle"

bin
Set via BUNDLE_BIN: "/bundle/bin"

gemfile
Set via BUNDLE_GEMFILE: "/product_name/Gemfile"

この後に最初のコマンドを実行したら、実行されました。

22
17
3

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
22
17