Rails 本地安装 RubyChina 时,遇到一些问题,求解答

diguage · 2014年01月25日 · 最后由 diguage 回复于 2014年02月10日 · 4200 次阅读

RubyChina 的下载,MongoDB、Redis、Memcached 等的安装略过。

uninitialized constant BSON

下载后,bundle 好之后,ruby setup.rb时遇到如下问题:

ruby-china git:(master)  >ruby setup.rb
Now Installing Ruby China...
================================================================================

Checking Package Dependencies...
--------------------------------------------------------------------------------
Bundler                                                                    [Yes]
MongoDB 2.0+                                                               [Yes]
Redis 2.0+                                                                 [Yes]
Memcached 1.4+                                                             [Yes]
ImageMagick 6.5+                                                           [Yes]
--------------------------------------------------------------------------------

Configure
--------------------------------------------------------------------------------
Your MongoDB host (default: 127.0.0.1:27017):
Your Redis host (default: 127.0.0.1:6379):
--------------------------------------------------------------------------------

Install gems...                                                           [Done]
Seed default data...rake aborted!
uninitialized constant BSON
/home/vagrant/.rvm/gems/ruby-2.0.0-p247@ruby-china/bundler/gems/mongoid-9b3bc1264032/lib/mongoid/extensions.rb:2:in `<top (required)>'
/home/vagrant/.rvm/gems/ruby-2.0.0-p247@ruby-china/bundler/gems/mongoid-9b3bc1264032/lib/mongoid/document.rb:4:in `<top (required)>'
/home/vagrant/.rvm/gems/ruby-2.0.0-p247@ruby-china/bundler/gems/mongoid-9b3bc1264032/lib/mongoid.rb:21:in `<top (required)>'
/home/vagrant/.rvm/gems/ruby-2.0.0-p247@global/gems/bundler-1.5.2/lib/bundler/runtime.rb:76:in `require'
/home/vagrant/.rvm/gems/ruby-2.0.0-p247@global/gems/bundler-1.5.2/lib/bundler/runtime.rb:76:in `block (2 levels) in require'
/home/vagrant/.rvm/gems/ruby-2.0.0-p247@global/gems/bundler-1.5.2/lib/bundler/runtime.rb:72:in `each'
/home/vagrant/.rvm/gems/ruby-2.0.0-p247@global/gems/bundler-1.5.2/lib/bundler/runtime.rb:72:in `block in require'
/home/vagrant/.rvm/gems/ruby-2.0.0-p247@global/gems/bundler-1.5.2/lib/bundler/runtime.rb:61:in `each'
/home/vagrant/.rvm/gems/ruby-2.0.0-p247@global/gems/bundler-1.5.2/lib/bundler/runtime.rb:61:in `require'
/home/vagrant/.rvm/gems/ruby-2.0.0-p247@global/gems/bundler-1.5.2/lib/bundler.rb:131:in `require'
/home/vagrant/ruby-china/config/application.rb:11:in `<top (required)>'
/home/vagrant/ruby-china/Rakefile:4:in `require'
/home/vagrant/ruby-china/Rakefile:4:in `<top (required)>'
/home/vagrant/.rvm/gems/ruby-2.0.0-p247@ruby-china/bin/ruby_executable_hooks:15:in `eval'
/home/vagrant/.rvm/gems/ruby-2.0.0-p247@ruby-china/bin/ruby_executable_hooks:15:in `<main>'
(See full trace by running task with --trace)
                                                      [Done]

Ruby China Successfully Installed.

看到了Ruby China Successfully Installed.我窃以为安装成功了,然后直接运行rails s,结果又报和上面一样的错误。日志如下:

ruby-china git:(master)  >rails s
/home/vagrant/.rvm/gems/ruby-2.0.0-p247@ruby-china/bundler/gems/mongoid-9b3bc1264032/lib/mongoid/extensions.rb:2:in `<top (required)>': uninitialized constant BSON (NameError)
    from /home/vagrant/.rvm/gems/ruby-2.0.0-p247@ruby-china/bundler/gems/mongoid-9b3bc1264032/lib/mongoid/document.rb:4:in `<top (required)>'
    from /home/vagrant/.rvm/gems/ruby-2.0.0-p247@ruby-china/bundler/gems/mongoid-9b3bc1264032/lib/mongoid.rb:21:in `<top (required)>'
    from /home/vagrant/.rvm/gems/ruby-2.0.0-p247@global/gems/bundler-1.5.2/lib/bundler/runtime.rb:76:in `require'
    from /home/vagrant/.rvm/gems/ruby-2.0.0-p247@global/gems/bundler-1.5.2/lib/bundler/runtime.rb:76:in `block (2 levels) in require'
    from /home/vagrant/.rvm/gems/ruby-2.0.0-p247@global/gems/bundler-1.5.2/lib/bundler/runtime.rb:72:in `each'
    from /home/vagrant/.rvm/gems/ruby-2.0.0-p247@global/gems/bundler-1.5.2/lib/bundler/runtime.rb:72:in `block in require'
    from /home/vagrant/.rvm/gems/ruby-2.0.0-p247@global/gems/bundler-1.5.2/lib/bundler/runtime.rb:61:in `each'
    from /home/vagrant/.rvm/gems/ruby-2.0.0-p247@global/gems/bundler-1.5.2/lib/bundler/runtime.rb:61:in `require'
    from /home/vagrant/.rvm/gems/ruby-2.0.0-p247@global/gems/bundler-1.5.2/lib/bundler.rb:131:in `require'
    from /home/vagrant/ruby-china/config/application.rb:11:in `<top (required)>'
    from /home/vagrant/.rvm/gems/ruby-2.0.0-p247@ruby-china/gems/railties-4.0.2/lib/rails/commands.rb:74:in `require'
    from /home/vagrant/.rvm/gems/ruby-2.0.0-p247@ruby-china/gems/railties-4.0.2/lib/rails/commands.rb:74:in `block in <top (required)>'
    from /home/vagrant/.rvm/gems/ruby-2.0.0-p247@ruby-china/gems/railties-4.0.2/lib/rails/commands.rb:71:in `tap'
    from /home/vagrant/.rvm/gems/ruby-2.0.0-p247@ruby-china/gems/railties-4.0.2/lib/rails/commands.rb:71:in `<top (required)>'
    from script/rails:6:in `require'
    from script/rails:6:in `<main>'

然后,搜问题解答,搜到如下解决方法: uninitialized constant BSON::ByteBuffer (Heroku) 安装所述,在Gemfile中,增加如下一行

gem "bson", "~> 2.2.0"

找不到合适版本的 moped

然后,运行运行bundle命令,但是却报如下错误:

ruby-china git:(master)  >bundle
Fetching source index from http://ruby.taobao.org/
Resolving dependencies...
Bundler could not find compatible versions for gem "moped":
  In snapshot (Gemfile.lock):
    moped (1.5.0)

  In Gemfile:
    mongoid (>= 0) ruby depends on
      moped (~> 2.0.beta3) ruby

Running `bundle update` will rebuild your snapshot from scratch, using only
the gems in your Gemfile, which may resolve the conflict.

找不到 frontier 分支

根据提示,我运行了bundle update命令,结果又报如下错误:

ruby-china git:(master)  >bundle update
Updating git://github.com/mongoid/mongoid.git
Updating git://github.com/huacnlee/bootstrap-helper.git
Updating git://github.com/intridea/grape.git
fatal: ambiguous argument 'frontier': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions
Retrying git rev-parse frontier due to error (2/3): Bundler::Source::Git::GitCommandError Git error: command `git rev-parse frontier` in directory /home/vagrant/.rvm/gems/ruby-2.0.0-p247@ruby-china/cache/bundler/git/grape-c77c5fb0336b00082cc45f4584f3dddedc8cb513 has failed.
If this error persists you could try removing the cache directory '/home/vagrant/.rvm/gems/ruby-2.0.0-p247@ruby-china/cache/bundler/git/grape-c77c5fb0336b00082cc45f4584f3dddedc8cb513'
fatal: ambiguous argument 'frontier': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions
Retrying git rev-parse frontier due to error (3/3): Bundler::Source::Git::GitCommandError Git error: command `git rev-parse frontier` in directory /home/vagrant/.rvm/gems/ruby-2.0.0-p247@ruby-china/cache/bundler/git/grape-c77c5fb0336b00082cc45f4584f3dddedc8cb513 has failed.
If this error persists you could try removing the cache directory '/home/vagrant/.rvm/gems/ruby-2.0.0-p247@ruby-china/cache/bundler/git/grape-c77c5fb0336b00082cc45f4584f3dddedc8cb513'
fatal: ambiguous argument 'frontier': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions
Git error: command `git rev-parse frontier` in directory /home/vagrant/.rvm/gems/ruby-2.0.0-p247@ruby-china/cache/bundler/git/grape-c77c5fb0336b00082cc45f4584f3dddedc8cb513 has failed.
If this error persists you could try removing the cache directory '/home/vagrant/.rvm/gems/ruby-2.0.0-p247@ruby-china/cache/bundler/git/grape-c77c5fb0336b00082cc45f4584f3dddedc8cb513'

我查了一下 Grape 的 Github 页面,确实没有frontier的分支了。但是,不知道为什么 RubyChina 的Gemfiel文件中没有更新?

actionpack 依赖版本冲突

我把 Grape 的声明方式修改为gem 'grape'了,目前执行bundle update,但是却报如下错误:

ruby-china git:(master)  >bundle update
Updating git://github.com/mongoid/mongoid.git
Updating git://github.com/huacnlee/bootstrap-helper.git
Updating git://github.com/searls/jasmine-rails.git
Fetching source index from http://ruby.taobao.org/
Resolving dependencies...
Bundler could not find compatible versions for gem "actionpack":
  In Gemfile:
    rails (= 4.0.2) ruby depends on
      actionpack (= 4.0.2) ruby

    actionpack-action_caching (= 1.0.0) ruby depends on
      actionpack (4.1.0.beta1)

环境

  • Ubuntu 12.04 32 位
  • ruby-2.0.0-p247
  • Rails 4.0.2
  • MongoDB shell version: 2.4.9
  • Redis 2.8.3
  • Memcached 1.4.13

问题列表

  1. uninitialized constant BSON (NameError)--这个通过增加gem bson解决了;
  2. Bundler could not find compatible versions for gem "moped"--提示bundle update,但是目前还没有跑通过。还要再看看;
  3. fatal: ambiguous argument 'frontier': unknown revision or path not in the working tree.--这个通过直接引用gem 'grape',而不是走 Github 分支,可以了;
  4. Bundler could not find compatible versions for gem "actionpack"

求解答。

自己顶一下。

数据库服务器没开吧?

#2 楼 @dothide 用到是 MongoDB 的,开启了。

支持地瓜哥

按照他说的 bundle update一下实验

#5 楼 @jasl 试了,不行。 提示actionpack-action_caching的版本又冲突。过年家里没联网,我抽空再试试。

#4 楼 @cisolarix 谢谢!我抽空再试试。有结果,及时反馈。哈哈

需要 登录 后方可回复, 如果你还没有账号请 注册新账号