我在尝试mysql2为Rails 安装gem 时遇到了一些问题.当我尝试通过运行安装它bundle install或gem install mysql2它给我以下错误:
安装mysql2时出错:错误:无法构建gem原生扩展.
我该如何修复并成功安装mysql2?
最近我在Windows上安装了Ruby 2.2.1和新的RubyInstaller.为了检查一切是否正常工作,我进入了一个rails应用程序并且运行bundle install正常.但是,当我运行测试时bunle exec rake test,我收到以下错误:
rake aborted!
LoadError: cannot load such file -- nokogiri/nokogiri
D:/Dev/Grummle/config/application.rb:7:in `<top (required)>'
D:/Dev/Grummle/Rakefile:4:in `<top (required)>'
LoadError: cannot load such file -- nokogiri/2.2/nokogiri
D:/Dev/Grummle/config/application.rb:7:in `<top (required)>'
D:/Dev/Grummle/Rakefile:4:in `<top (required)>'
(See full trace by running task with --trace)
Run Code Online (Sandbox Code Playgroud)
Bundler说是的Using nokogiri 1.6.5.此外,rake任务在Ruby 2.1.5中运行良好.我很欣赏有关如何解决问题的想法.谢谢!:)
该命令rails server抛出此错误.
C:/Ruby200/lib/ruby/gems/2.0.0/gems/mysql2-0.3.11-x86-mingw32/lib/mysql2/mysql2.rb:2:in `require': cannot load
such file -- mysql2/2.0/mysql2 (LoadError)
Run Code Online (Sandbox Code Playgroud)
我使用的红宝石2.0.0从RubyInstaller在Windows XP的方块.
我弄清楚问题是什么,但我不知道如何解决它.问题是gem中没有任何2.0/目录mysql2-0.3.11-x86-mingw32.这是rails从Gemfile安装为其依赖项的gem:
GEM
remote: https://rubygems.org/
specs:
... many gems here
mysql2 (0.3.11-x86-mingw32)
... many gems here
DEPENDENCIES
...
mysql2
...
Run Code Online (Sandbox Code Playgroud)
这是该mysql2.rb文件中的内容:
# C:\Ruby200\lib\ruby\gems\2.0.0\gems\mysql2-0.3.11-x86-mingw32\lib\mysql2\mysql2.rb
RUBY_VERSION =~ /(\d+.\d+)/
require "mysql2/#{$1}/mysql2" # <<-- this is that #2 line that throws an error
Run Code Online (Sandbox Code Playgroud)
很明显,它采用当前的Ruby版本号并将其用作路径段来访问某个mysql2文件.实际上它是mysql2.so文件.当我使用Ruby 2.0.0时,路径段是2.0:
mysql2/2.0/mysql2 …Run Code Online (Sandbox Code Playgroud)