Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Problems installing mysql2 gem

When I run bundle install in my project I get an error where it struggles to 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. 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.

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:

"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

Ruby version '2.6.1'

How do I fix this?

like image 698
Cinta Avatar asked Feb 22 '19 13:02

Cinta


2 Answers

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
like image 127
Cinta Avatar answered Sep 29 '22 13:09

Cinta


Older solutions to install mysql2 set bundler config to have a --with-cppflags option, which is what clang is now complaining about not supporting.

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
like image 26
Xavier Shay Avatar answered Sep 29 '22 14:09

Xavier Shay