4

尝试在 Cent OS 6.3 上使用 ruby​​2.0.0-p247 安装 mysql2 gem。

这一切在 ruby​​-1.9.3-p324 上运行良好,但使用 RVM 安装 ruby​​2。我的测试代码如下

需要“mysql2”

放“测试”

对上面的代码运行 ruby​​,我得到了错误:

/usr/local/rvm/rubies/ruby-2.0.0-p247/lib/ruby/site_ruby/2.0.0/rubygems/custom_require.rb:36:in require': cannot load such file -- mysql2/mysql2 (LoadError) from /usr/local/rvm/rubies/ruby-2.0.0-p247/lib/ruby/site_ruby/2.0.0/rubygems/custom_require.rb:36:in require'来自/usr/local/rvm/gems/ruby- 2.0.0-p247/gems/mysql2-0.3.11/lib/mysql2.rb:9:in <top (required)>' from /usr/local/rvm/rubies/ruby-2.0.0-p247/lib/ruby/site_ruby/2.0.0/rubygems/custom_require.rb:60:in 需要'来自 /usr/local/rvm/rubies/ruby-2.0.0-p247/lib/ruby/site_ruby/2.0 .0/rubygems/custom_require.rb:60:in rescue in require' from /usr/local/rvm/rubies/ruby-2.0.0-p247/lib/ruby/site_ruby/2.0.0/rubygems/custom_require.rb:35:in require' from mysqltest.rb:1:in `'

bundle install / gem install mysql2 工作正常,它只是在尝试使用 gem。我用谷歌搜索了这个,常见的答案是没有安装 libmysql-devel 包等,情况并非如此,因为它在 ruby​​-1.9.3 下工作正常。

文件在磁盘上

[git@rubyland-provisioner mysql2-0.3.11]$ ls lib/mysql2
client.rb  em.rb  error.rb  result.rb  version.rb

[git@rubyland-provisioner mysql2-0.3.11]$ ls ext/mysql2
client.c  client.o    Makefile  mysql2_ext.c  mysql2_ext.o  result.c  result.o
client.h  extconf.rb  mkmf.log  mysql2_ext.h  mysql2.so     result.h  wait_for_single_fd.h

如果我手动将 mysql2.so(由 gem install 构建,我检查了时间戳)复制到 lib/mysql2 目录,一切都按预期工作。

我对 Ruby 很陌生;我错过了什么?为什么 gem install 没有将此文件复制到正确的位置。

谢谢

安德鲁

4

2 回答 2

2

This turned out to be a bug in RVM with the version of RubyGems installed by RVM. You need to make sure that the RubyGems that is installed is 2.x. This wasn't the case for me, RVM had either not installed RubyGems at all, or, not installed the correct version; we ultimately got some help from the RVM channel on IRC.

There's a bit more detail on twitter off the back of the conversation we had.

https://twitter.com/mpapis/status/357160111883563008

于 2013-07-18T08:24:54.247 回答
0

just downgrade the mysql2 version. In my case, I used '0.2.6' version and it worked for me.

  gem 'mysql2', '0.2.6'

with ruby version 2.0.0 and gem version 1.8.25

于 2014-01-22T10:34:37.763 回答