简体   繁体   中英

`rails new my_app` returns "Could not locate Gemfile or .bundle/ directory"

I tried creating a new Rails app, and got this error:

% bundle exec rails new my_app
Could not locate Gemfile or .bundle/ directory

I tried running bundle and got the same error.

What am I doing wrong?

Just leave off the bundle exec part of the command:

% bundle exec rails new my_app 
Could not locate Gemfile or .bundle/ directory

% rails new my_app
      create
      create  README.md
      create  Rakefile
      create  .ruby-version
      create  config.ru
      create  .gitignore
      create  Gemfile
         run  git init from "."
      (etc.)

In the case of generating a new rails app (something that I've only done 3-4 times in several years as a full-time Rails developer), there is no Gemfile yet...just like the error suggests. rails new my_app is probably the only command in the Rails environment that can't run under bundler.

This may be a particular gotcha if you've got an alias rails=bundle exec rails in your shell, or if your fingers are just trained to always type bundle exec for rails commands. In this case, you could remove that alias ( unalias rails ), but it's probably better to bypass the alias just this once by enclosing it in quotes:

"rails" new my_app
      create
      create  README.md
      create  Rakefile
      (etc.)

what about :

  • rails new app_name
  • cd app_name
  • bundle

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM