【问题标题】:attempting to execute any command starting "rails" yields "Could not locate Gemfile"尝试执行任何以“rails”开头的命令会产生“Could not locate Gemfile”
【发布时间】:2013-02-24 02:03:52
【问题描述】:

我正在尝试安装一个新的 rails 应用程序。我的机器上已经安装了几个 rails 应用程序,一切正常。

$ rails new app
Could not locate Gemfile

然后我想我会运行一个跟踪来弄清楚发生了什么,因为无论如何你都不希望有一个Gemfile,因为通常上面的命令会创建一个全新的 Rails 应用程序一个名为app 的目录,其中包含Gemfile

$ rails new app --trace
Could not locate Gemfile

因此,我尝试通过此详细指南在我的计算机上重新安装所有内容:

http://railsapps.github.com/installing-rails.html#gems

在前 20 步左右之后,我得到了这个命令:

$ rake -v
Could not locate Gemfile

我认为我的设置有问题,但我看不到任何问题。

这是我的 rvm 设置:

$ rvm version

rvm 1.18.10 (latest) by Wayne E. Seguin <wayneeseguin@gmail.com>, Michal Papis <mpapis@gmail.com> [https://rvm.io/]

$ rvm list

rvm rubies

   jruby-1.6.7 [ x86_64 ]
   ruby-1.9.1-p431 [ i386 ]
   ruby-1.9.3-p194 [ x86_64 ]
   ruby-1.9.3-p286 [ x86_64 ]
   ruby-1.9.3-p327 [ x86_64 ]
=* ruby-1.9.3-p385 [ x86_64 ]

# => - current
# =* - current && default
#  * - default

$ rvm gemset list

gemsets for ruby-1.9.3-p385 (found in /Users/paul/.rvm/gems/ruby-1.9.3-p385)
   (default)
   global
=> rails32

这是安装在我的 rails32 gemset 上的 gems

$ gem list

*** LOCAL GEMS ***

actionmailer (3.2.12, 3.2.11)
actionpack (3.2.12, 3.2.11)
activemodel (3.2.12, 3.2.11)
activerecord (3.2.12, 3.2.11)
activeresource (3.2.12, 3.2.11)
activesupport (3.2.12, 3.2.11)
arel (3.0.2)
builder (3.0.4)
bundler (1.2.4)
erubis (2.7.0)
hike (1.2.1)
i18n (0.6.1)
journey (1.0.4)
json (1.7.7)
mail (2.4.4)
mime-types (1.21)
multi_json (1.6.1)
polyglot (0.3.3)
rack (1.4.5)
rack-cache (1.2)
rack-ssl (1.3.3)
rack-test (0.6.2)
rails (3.2.12, 3.2.11)
railties (3.2.12, 3.2.11)
rake (10.0.3)
rdoc (3.12.1)
rubygems-bundler (1.1.0)
rvm (1.11.3.6)
sprockets (2.2.2)
thor (0.17.0)
tilt (1.3.3)
treetop (1.4.12)
tzinfo (0.3.35)

捆绑器版本

$ bundle --version
Bundler version 1.2.4

.gemrc 文件

$ cat ~/.gemrc
---
:backtrace: false
:benchmark: false
:bulk_threshold: 1000
:sources:
- http://rubygems.org/
- https://rubygems.org
:update_sources: true
:verbose: true

一切似乎都很好,非常沮丧,请帮助。

【问题讨论】:

  • 您在执行rails -vrails -h 之类的操作时是否遇到同样的错误?
  • @Cluster 不幸的是,是的,我得到了相同的结果。有什么想法吗?
  • 如果你把bundle exec放在这些命令之前呢?
  • 我只是按照该文档中的说明进行操作,唯一的区别是我使用了最新的 ruby​​ 补丁 392,并且 rails new 工作正常。
  • @Cluster 我刚刚用补丁 392 再次尝试,结果相同。 bundle exec 也产生了相同的结果。

标签: ruby-on-rails ruby-on-rails-3.2 installation rvm gemfile


【解决方案1】:

此错误仅发生在以bundle exec 为前缀的命令或当前目录中没有Gemfilebundle install 的情况下。

我的假设是您可能正在运行启用bundler 的命令,请检查:

which rake

找出正在运行的命令。

【讨论】:

  • 谢谢!我在我的 .bash_profile 中将“bundle exec rails”别名为“rails”,您的评论让我们很容易弄清楚发生了什么。
  • 这也是我所做的。对于那些只想为那个 shell 会话覆盖别名的人,你可以这样做: alias rails='rails'.
【解决方案2】:
bundle install

在项目目录中为我修复了它。 之后,我遇到了这个错误:

您的 Gemfile 中有错误,Bundler 无法继续。

这已通过以下方式解决:

gem update bundler

然后我重新安装 Ruby 和 Rails 终于奏效了。只花了大约四个小时就让它工作了:-/

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-01-10
    • 2021-07-27
    • 2022-10-07
    相关资源
    最近更新 更多