无法激活mysql2(〜> 0.3.10),已激活mysql2-0.4.3

时间:2016-03-01 09:43:10

标签: ruby-on-rails ruby bundler

在运行rails应用程序时,我收到以下错误 -

DEPRECATION WARNING: Support for Rails < 4.1.0 will be dropped. (called from warn at /home/user/.rvm/rubies/ruby-2.1.6/lib/ruby/2.1.0/forwardable.rb:183)
/home/user/.rvm/gems/ruby-2.1.6/gems/signalfx-0.1.0/lib/signalfx/conf.rb:3:in `<top (required)>': Use RbConfig instead of obsolete and deprecated Config.
/home/user/.rvm/gems/ruby-2.1.6/gems/bundler-1.11.2/lib/bundler/rubygems_integration.rb:314:in `block in replace_gem': Please install the mysql2 adapter: `gem install activerecord-mysql2-adapter` (can't activate mysql2 (~> 0.3.10), already activated mysql2-0.4.3. Make sure all dependencies are added to Gemfile.) (LoadError)
    from /home/user/.rvm/gems/ruby-2.1.6/gems/activerecord-3.2.17/lib/active_record/connection_adapters/mysql2_adapter.rb:3:in `<top (required)>'
    from /home/user/.rvm/gems/ruby-2.1.6/gems/activesupport-3.2.17/lib/active_support/dependencies.rb:251:in `require'
    from /home/user/.rvm/gems/ruby-2.1.6/gems/activesupport-3.2.17/lib/active_support/dependencies.rb:251:in `block in require'
    from /home/user/.rvm/gems/ruby-2.1.6/gems/activesupport-3.2.17/lib/active_support/dependencies.rb:236:in `load_dependency'
    from /home/user/.rvm/gems/ruby-2.1.6/gems/activesupport-3.2.17/lib/active_support/dependencies.rb:251:in `require'

在gemfile中,我有条目:gem 'mysql2', '~> 0.3'

检查安装了哪个gem:

$ gem list|grep mysql2

activerecord-mysql2-adapter (0.0.3)
mysql2 (0.4.3)

如何解决此错误?

2 个答案:

答案 0 :(得分:5)

更新您的Gemfile,指定确切的版本

gem 'mysql2', '0.3.20'

然后运行

bundle update mysql2

这应该使用Gemfile

版本更新您的mysql2 gem

答案 1 :(得分:0)

通常可以通过在命令前添加bundle exec来避免这种情况 - 这将确保命令在捆绑的宝石而不是系统宝石的上下文中运行。

如果您为多个项目执行bundle install但未设置部署路径或以其他方式分离单个项目的已安装gem,则会发生这种情况。

e.g。 bundle exec rails s