【问题标题】:Ruby on Rails incompatible libraryRuby on Rails 不兼容的库
【发布时间】:2015-12-26 20:11:04
【问题描述】:

我刚刚开始查看 ruby​​ on rails 并且无法让服务器运行。我正在运行 ruby​​ 2.3.0 和 rails 4.2.5,在我有一个新的铁路项目后,我尝试运行 bin/rails server 但收到以下错误:

Warning: Running `gem pristine --all` to regenerate your installed gemspecs (and deleting then reinstalling your bundle if you use bundle --path) will improve the startup performance of Spring.
/Users/John/.rvm/gems/ruby-head/gems/json-1.8.3/lib/json/ext.rb:13:in `require': incompatible library version - /Users/John/.rvm/gems/ruby-head/gems/json-1.8.3/lib/json/ext/parser.bundle (fatal)
    from /Users/John/.rvm/gems/ruby-head/gems/json-1.8.3/lib/json/ext.rb:13:in `<module:Ext>'
    from /Users/John/.rvm/gems/ruby-head/gems/json-1.8.3/lib/json/ext.rb:12:in `<module:JSON>'
    from /Users/John/.rvm/gems/ruby-head/gems/json-1.8.3/lib/json/ext.rb:9:in `<top (required)>'
    from /Users/John/.rvm/gems/ruby-head/gems/json-1.8.3/lib/json.rb:58:in `require'
    from /Users/John/.rvm/gems/ruby-head/gems/json-1.8.3/lib/json.rb:58:in `<module:JSON>'
    from /Users/John/.rvm/gems/ruby-head/gems/json-1.8.3/lib/json.rb:54:in `<top (required)>'
    from /Users/John/.rvm/gems/ruby-head/gems/activesupport-4.2.5/lib/active_support/core_ext/object/json.rb:2:in `require'
    from /Users/John/.rvm/gems/ruby-head/gems/activesupport-4.2.5/lib/active_support/core_ext/object/json.rb:2:in `<top (required)>'
    from /Users/John/.rvm/gems/ruby-head/gems/activesupport-4.2.5/lib/active_support/core_ext/object.rb:12:in `require'
    from /Users/John/.rvm/gems/ruby-head/gems/activesupport-4.2.5/lib/active_support/core_ext/object.rb:12:in `<top (required)>'
    from /Users/John/.rvm/gems/ruby-head/gems/railties-4.2.5/lib/rails/configuration.rb:2:in `require'
    from /Users/John/.rvm/gems/ruby-head/gems/railties-4.2.5/lib/rails/configuration.rb:2:in `<top (required)>'
    from /Users/John/.rvm/gems/ruby-head/gems/railties-4.2.5/lib/rails/railtie.rb:2:in `require'
    from /Users/John/.rvm/gems/ruby-head/gems/railties-4.2.5/lib/rails/railtie.rb:2:in `<top (required)>'
    from /Users/John/.rvm/gems/ruby-head/gems/railties-4.2.5/lib/rails/engine.rb:1:in `require'
    from /Users/John/.rvm/gems/ruby-head/gems/railties-4.2.5/lib/rails/engine.rb:1:in `<top (required)>'
    from /Users/John/.rvm/gems/ruby-head/gems/railties-4.2.5/lib/rails/application.rb:7:in `require'
    from /Users/John/.rvm/gems/ruby-head/gems/railties-4.2.5/lib/rails/application.rb:7:in `<top (required)>'
    from /Users/John/.rvm/gems/ruby-head/gems/railties-4.2.5/lib/rails.rb:11:in `require'
    from /Users/John/.rvm/gems/ruby-head/gems/railties-4.2.5/lib/rails.rb:11:in `<top (required)>'
    from /Users/John/.rvm/gems/ruby-head/gems/railties-4.2.5/lib/rails/commands/server.rb:4:in `require'
    from /Users/John/.rvm/gems/ruby-head/gems/railties-4.2.5/lib/rails/commands/server.rb:4:in `<top (required)>'
    from /Users/John/.rvm/gems/ruby-head/gems/railties-4.2.5/lib/rails/commands/commands_tasks.rb:123:in `require'
    from /Users/John/.rvm/gems/ruby-head/gems/railties-4.2.5/lib/rails/commands/commands_tasks.rb:123:in `require_command!'
    from /Users/John/.rvm/gems/ruby-head/gems/railties-4.2.5/lib/rails/commands/commands_tasks.rb:73:in `server'
    from /Users/John/.rvm/gems/ruby-head/gems/railties-4.2.5/lib/rails/commands/commands_tasks.rb:39:in `run_command!'
    from /Users/John/.rvm/gems/ruby-head/gems/railties-4.2.5/lib/rails/commands.rb:17:in `<top (required)>'
    from /Users/John/Developer/Rails/blog/bin/rails:9:in `require'
    from /Users/John/Developer/Rails/blog/bin/rails:9:in `<top (required)>'
    from /Users/John/.rvm/gems/ruby-head/gems/spring-1.6.1/lib/spring/client/rails.rb:28:in `load'
    from /Users/John/.rvm/gems/ruby-head/gems/spring-1.6.1/lib/spring/client/rails.rb:28:in `call'
    from /Users/John/.rvm/gems/ruby-head/gems/spring-1.6.1/lib/spring/client/command.rb:7:in `call'
    from /Users/John/.rvm/gems/ruby-head/gems/spring-1.6.1/lib/spring/client.rb:28:in `run'
    from /Users/John/.rvm/gems/ruby-head/gems/spring-1.6.1/bin/spring:51:in `<top (required)>'
    from /Users/John/.rvm/gems/ruby-head/gems/spring-1.6.1/lib/spring/binstub.rb:11:in `load'
    from /Users/John/.rvm/gems/ruby-head/gems/spring-1.6.1/lib/spring/binstub.rb:11:in `<top (required)>'
    from /Users/John/.rvm/rubies/ruby-head/lib/ruby/site_ruby/2.3.0/rubygems/core_ext/kernel_require.rb:54:in `require'
    from /Users/John/.rvm/rubies/ruby-head/lib/ruby/site_ruby/2.3.0/rubygems/core_ext/kernel_require.rb:54:in `require'
    from /Users/John/Developer/Rails/blog/bin/spring:13:in `<top (required)>'
    from bin/rails:3:in `load'
    from bin/rails:3:in `<main>'

宝石列表显示我有json (1.8.3, 1.8.2)。我还尝试重新安装 rails 并通过 rvm 更新我的 ruby​​ 版本。知道有什么问题吗?我试过在网上四处寻找,但有点卡住了,尤其是因为我以前从未使用过 rails,而且只有一点 ruby​​。

【问题讨论】:

  • 您使用的是 Windows 还是 Linux?
  • 好像没有编译json的原生扩展。
  • @RichPeck 我正在使用 OS X
  • 运行bundle exec rails server时是否还会出现同样的问题? bundle check 是否运行成功?您的Gemfile.lock 中是否提到了json
  • @Raffael bundle exec rails server 也失败了。 bundle check 运行成功返回 The Gemfile's dependencies are satisfied。 json 多次出现在 Gemfile.lock 中,例如cat gemfile.lock | grep json 给我json (~&gt; 1.7, &gt;= 1.7.7) multi_json (~&gt; 1.2) json (1.8.3) multi_json (1.11.2) json (~&gt; 1.4) json (~&gt; 1.7, &gt;= 1.7.7) json (&gt;= 1.8.0)

标签: ruby-on-rails ruby json


【解决方案1】:

在您的 ruby​​ 环境中有些东西变得奇怪/损坏了。我会责怪rvm。我个人不是rvm的粉丝。

但你可以试试gem uninstall json,按照提示卸载所有版本。然后再次bundle install。然后希望你能得到解决。

【讨论】:

  • 我刚试过这个,但没有运气。和之前编辑一样:拼写
  • 刚刚注意到我在使用 sqlite3 之后遇到了问题。为此做了同样的事情,debug_inspector et voila 它工作了!
  • 您可以gem pristine --all自动卸载并重新安装当前环境下所有已安装的gem。这需要一段时间。巧合的是,您的输出顶部的警告所推荐的是同一件事,尽管它出于不同的原因推荐它,以使 Spring 更好地工作(我自己不使用 Spring),我认为推荐它是因为它注意到您安装的 gem 的 ruby​​ 版本比您当前使用的版本更早,除了一些已编译的 gem 之外,这通常没问题。
  • 即使在使用 gem pristine --all 之后,我也发生了这个错误。最后,我不得不继续进行 gem 卸载,然后进行捆绑安装,直到它最终可以工作。
  • @jrochkind, gem pristine --all 为我工作。谢谢!
【解决方案2】:

在使用不同的 ruby​​ 版本(从 2.3.0 -> 2.3.3)后,我遇到了与您描述的类似的问题。

我发现正在运行:

$ gem install bundler

然后:

$ bundle install

...对我来说很有魅力。这重新安装了我在 Gemfile 中需要的所有包,没有任何依赖问题。

【讨论】:

    【解决方案3】:

    删除vendor 并运行bundle install 可以解决这个问题。它对我有用。

    【讨论】:

    • 这在brew 引入了一些新的 Ruby 版本之后有所帮助。
    【解决方案4】:

    看起来json gem 的从未版本已经存在并被 rails 拾取。您可以手动删除版本:

    gem uninstall json -v 1.8.2
    

    或者,由于您已经在使用 RVM,create 是该项目特定的 gemset。

    【讨论】:

    • 你不应该需要做这些事情,安装多个版本的 json gem 应该是很可能的,你的应用程序应该使用它的依赖要求中指定的那个,因为那是捆绑器做什么。但我也不确定发生了什么。但如果我是你,我不会尝试通过这些建议来解决它,这很可能会在以后导致更多的混乱。
    • 由于这是一个带有原生扩展的 gem,我同意卸载并重新安装。显然原生扩展是用1.8.2 编译的,1.8.3 不能使用它们。
    • 无法卸载 json 1.8.2,因为它是默认 gem
    猜你喜欢
    • 2015-03-28
    • 1970-01-01
    • 2012-02-23
    • 2015-11-04
    • 2023-03-14
    • 1970-01-01
    • 2011-05-10
    • 2021-04-11
    • 1970-01-01
    相关资源
    最近更新 更多