简体   繁体   English

安装mysql2 gem的问题

[英]Problems installing mysql2 gem

When I run bundle install in my project I get an error where it struggles to install mysql.当我在我的项目中运行 bundle install 时,我收到一个错误,说明它很难安装 mysql。 It was wierd because the project worked fine until I cancelled the server to update my db record with rails and I got an rails error.这很奇怪,因为该项目运行良好,直到我取消服务器以使用 rails 更新我的数据库记录并且出现 rails 错误。 When I ran bundle install alot of my gems were missing and now I'm trying to reinstall all the gems but it keeps failing at mysql2.当我运行 bundle install 时,我的很多 gem 都丢失了,现在我正在尝试重新安装所有 gem,但它在 mysql2 上一直失败。

Error log: .rvm/gems/ruby-2.6.1/extensions/x86_64-darwin-18/2.6.0-static/mysql2-0.5.2/gem_make.out output:错误日志:.rvm/gems/ruby-2.6.1/extensions/x86_64-darwin-18/2.6.0-static/mysql2-0.5.2/gem_make.out 输出:

"clang -o conftest -I/Users/cinta/.rbenv/versions/2.6.1/include/ruby-2.6.0/x86_64-darwin18 -I/Users/cinta/.rbenv/versions/2.6.1/include/ruby-2.6.0/ruby/backward -I/Users/cinta/.rbenv/versions/2.6.1/include/ruby-2.6.0 -I. -I/Users/cinta/.rbenv/versions/2.6.1/include  -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -D_DARWIN_UNLIMITED_SELECT -D_REENTRANT    -O3 -Wno-error=shorten-64-to-32  -pipe conftest.c  -L. -L/Users/cinta/.rbenv/versions/2.6.1/lib -L/usr/local/opt/openssl/lib --with-cppflags=-I/usr/local/opt/openssl/include     -lruby.2.6-static -framework Security -framework Foundation -lpthread -ldl -lobjc   "
clang: error: unsupported option '--with-cppflags=-I/usr/local/opt/openssl/include'
checked program was:
/* begin */
1: #include "ruby.h"
2: 
3: int main(int argc, char **argv)
4: {
5:   return 0;
6: }
/* end */

I'm using a macbook pro, OS Mojave 10.14.1我使用的是 macbook pro,OS Mojave 10.14.1

Ruby version '2.6.1' Ruby 版本“2.6.1”

How do I fix this?我该如何解决?

Somehow, after several tries typing this worked:不知何故,经过多次尝试输入此内容后:

$ gem install mysql2 -- --srcdir=/usr/local/mysql/include

But then the server wouldn't run.但随后服务器将无法运行。

But typing from this answer , worked:但是从这个答案中输入,有效:

$ gem uninstall mysql2
$ gem install mysql2 --platform=ruby

Older solutions to install mysql2 set bundler config to have a --with-cppflags option, which is what clang is now complaining about not supporting.安装 mysql2 的旧解决方案将 bundler 配置设置为具有--with-cppflags选项,这是 clang 现在抱怨不支持的原因。

It doesn't appear that option is needed anymore.似乎不再需要该选项了。 I had the same error as you, and now the following worked for me.我和你有同样的错误,现在以下对我有用。

bundle config --local build.mysql2 "--with-ldflags=-L/usr/local/opt/openssl/lib"
bundle install

The simple and fastest solution is最简单和最快的解决方案是

gem install mysql2 -v '0.5.2' -- --with-ldflags=-L/usr/local/opt/openssl/lib --with-cppflags=-I/usr/local/opt/openssl/include

Reference: https://gist.github.com/fernandoaleman/ee3ac6957c2ba4f7d7d33a251d58b191参考: https : //gist.github.com/fernandoaleman/ee3ac6957c2ba4f7d7d33a251d58b191

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM