由于“mysql2”gem,我无法运行“bundle update”

我在Gemfile中有这个:

gem 'mysql2' 

但是当我运行bundle update时 ,我收到以下错误消息:

 An error occurred while installing mysql2 (0.3.16), and Bundler cannot continue. Make sure that `gem install mysql2 -v '0.3.16'` succeeds before bundling. 

我试着把它移到生产部分,像这样:

 group :production do gem 'mysql2' end 

但是在运行bundle更新后 ,结果是一样的。 此部分仅在生产模式下处理,还是不处理?

如何摆脱localhost上的此错误消息?

编辑:整个错误消息:

 Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension. /Users/radek/.rvm/rubies/ruby-1.9.3-p385/bin/ruby extconf.rb checking for ruby/thread.h... *** extconf.rb failed *** Could not create Makefile due to some reason, probably lack of necessary libraries and/or headers. Check the mkmf.log file for more details. You may need configuration options. Provided configuration options: --with-opt-dir --with-opt-include --without-opt-include=${opt-dir}/include --with-opt-lib --without-opt-lib=${opt-dir}/lib --with-make-prog --without-make-prog --srcdir=. --curdir --ruby=/Users/radek/.rvm/rubies/ruby-1.9.3-p385/bin/ruby /Users/radek/.rvm/rubies/ruby-1.9.3-p385/lib/ruby/1.9.1/mkmf.rb:381:in `try_do': The compiler failed to generate an executable file. (RuntimeError) You have to install development tools first. from /Users/radek/.rvm/rubies/ruby-1.9.3-p385/lib/ruby/1.9.1/mkmf.rb:506:in `try_cpp' from /Users/radek/.rvm/rubies/ruby-1.9.3-p385/lib/ruby/1.9.1/mkmf.rb:931:in `block in have_header' from /Users/radek/.rvm/rubies/ruby-1.9.3-p385/lib/ruby/1.9.1/mkmf.rb:790:in `block in checking_for' from /Users/radek/.rvm/rubies/ruby-1.9.3-p385/lib/ruby/1.9.1/mkmf.rb:284:in `block (2 levels) in postpone' from /Users/radek/.rvm/rubies/ruby-1.9.3-p385/lib/ruby/1.9.1/mkmf.rb:254:in `open' from /Users/radek/.rvm/rubies/ruby-1.9.3-p385/lib/ruby/1.9.1/mkmf.rb:284:in `block in postpone' from /Users/radek/.rvm/rubies/ruby-1.9.3-p385/lib/ruby/1.9.1/mkmf.rb:254:in `open' from /Users/radek/.rvm/rubies/ruby-1.9.3-p385/lib/ruby/1.9.1/mkmf.rb:280:in `postpone' from /Users/radek/.rvm/rubies/ruby-1.9.3-p385/lib/ruby/1.9.1/mkmf.rb:789:in `checking_for' from /Users/radek/.rvm/rubies/ruby-1.9.3-p385/lib/ruby/1.9.1/mkmf.rb:930:in `have_header' from extconf.rb:9:in `' Gem files will remain installed in /Users/radek/.rvm/gems/ruby-1.9.3-p385/gems/mysql2-0.3.16 for inspection. Results logged to /Users/radek/.rvm/gems/ruby-1.9.3-p385/gems/mysql2-0.3.16/ext/mysql2/gem_make.out An error occurred while installing mysql2 (0.3.16), and Bundler cannot continue. Make sure that `gem install mysql2 -v '0.3.16'` succeeds before bundling. 

谢谢

在Ubuntu上,运行

 sudo apt-get install libmysqlclient-dev 

或者,如果您使用MariaDB,请运行

 sudo apt-get install libmariadbclient-dev 

在Gemfile中添加: –

 gem 'mysql2', '0.3.16' 

然后:-

 bundle install 

之后尝试: –

 bundle update 

看起来你的机器上没有安装mysql2 gem 。当你使用Mac OSX ,你应该像这样安装mysql2 gem

 gem install mysql2 -- --with-mysql-dir=/usr/local/opt/mysql/ 

如果上述命令不起作用,请尝试这样做

 sudo gem install mysql -- --with-mysql-config=/usr/local/mysql/bin/mysql_config 

并尝试后

 bundle install 

这应该可以解决错误。

资源

我刚刚通过$ brew install mysql ,它解决了这个问题。

我最终得到了一个几乎相同的错误消息,试图在没有安装gcc-c++的机器上构建; mkmf无法编译一个简单的c程序,因为编译器没有编译。

如果你在CentOS上,你想要sudo yum install gcc-c++ 。 在Ubuntu上,它是sudo apt-get install g++ 。 旧版本的ruby-devel没有依赖于g++ ,这有点令人失望。