尝试创建新应用程序时,Rails无法找到Gemfile

时间:2017-02-28 21:09:01

标签: ruby-on-rails ruby

我是Rails的新手,我尝试创建一个新的应用程序(在MacOS上)。我通过rvm安装了Ruby,Rails和bundler。

$ ruby -v
ruby 2.4.0p0 (2016-12-24 revision 57164) [x86_64-darwin16]
$ gem -v
2.6.10
$ bundler -v
Bundler version 1.14.5

我尝试像这样创建应用程序:

$ mkdir au5
$ cd au5
$ rvm use ruby-2.4.0@au5 --ruby-version --create
$ gem install rails
$ rails new au5
/Users/user/.rvm/gems/ruby-2.4.0@au5/gems/bundler-1.14.5/lib/bundler/shared_helpers.rb:24:in `default_gemfile': Could not locate Gemfile (Bundler::GemfileNotFound)
    from /Users/user/.rvm/gems/ruby-2.4.0@au5/gems/bundler-1.14.5/lib/bundler/shared_helpers.rb:29:in `default_lockfile'
    from /Users/user/.rvm/gems/ruby-2.4.0@au5/gems/bundler-1.14.5/lib/bundler.rb:307:in `default_lockfile'
    from /Users/user/bin/spring:10:in `<top (required)>'
    from bin/rails:3:in `load'
    from bin/rails:3:in `<main>'

编辑1: rails -v给了我:

$ gem install rails
Successfully installed rails-5.0.1
Parsing documentation for rails-5.0.1
Done installing documentation for rails after 0 seconds
1 gem installed
$ rails -v
/Users/user/.rvm/gems/ruby-2.4.0@au5/gems/bundler-1.14.5/lib/bundler/shared_helpers.rb:24:in `default_gemfile': Could not locate Gemfile (Bundler::GemfileNotFound)
    from /Users/user/.rvm/gems/ruby-2.4.0@au5/gems/bundler-1.14.5/lib/bundler/shared_helpers.rb:29:in `default_lockfile'
    from /Users/user/.rvm/gems/ruby-2.4.0@au5/gems/bundler-1.14.5/lib/bundler.rb:307:in `default_lockfile'
    from /Users/user/bin/spring:10:in `<top (required)>'
    from bin/rails:3:in `load'
    from bin/rails:3:in `<main>'

编辑2:尝试创建空的Gemfile:

$ touch Gemfile
$ echo "source 'https://rubygems.org'" > Gemfile
$ gem install bundler
Successfully installed bundler-1.14.5
Parsing documentation for bundler-1.14.5
Done installing documentation for bundler after 3 seconds
1 gem installed
$ rails new au5
/Users/user/.rvm/gems/ruby-2.4.0@au5/gems/bundler-1.14.5/lib/bundler/shared_helpers.rb:24:in `default_gemfile': Could not locate Gemfile (Bundler::GemfileNotFound)
    from /Users/user/.rvm/gems/ruby-2.4.0@au5/gems/bundler-1.14.5/lib/bundler/shared_helpers.rb:29:in `default_lockfile'
    from /Users/user/.rvm/gems/ruby-2.4.0@au5/gems/bundler-1.14.5/lib/bundler.rb:307:in `default_lockfile'
    from /Users/user/bin/spring:10:in `<top (required)>'
    from bin/rails:3:in `load'
    from bin/rails:3:in `<main>'

编辑3:这些是项目文件夹中的文件:

$ ls -la
total 24
drwxr-xr-x  5 user  1694527156  170 Feb 28 22:28 .
drwxr-xr-x  8 user  1694527156  272 Feb 28 22:26 ..
-rw-r--r--  1 user  1694527156    4 Feb 28 22:26 .ruby-gemset
-rw-r--r--  1 user  1694527156   11 Feb 28 22:26 .ruby-version
-rw-r--r--  1 user  1694527156   30 Feb 28 22:28 Gemfile

2 个答案:

答案 0 :(得分:0)

您是否尝试过创建一个空的Gemfile

touch Gemfile
echo "source 'https://rubygems.org'" > Gemfile

还要确保安装bundler

gem install bundler

答案 1 :(得分:-1)

使用rbenv,有一个rehash函数可以修复(除其他外)与已安装的gem相关的路径。当您安装具有可执行脚本的gem时,rbenv有时会混淆并需要刷新环境。

我不知道rvm是否有类似的机制;我没有安装它,粗略的谷歌没有显示任何东西。但你可能想开始寻找那里。

(并考虑切换到rbenv,它似乎远不那么古怪)