brianmario / mysql2

A modern, simple and very fast Mysql library for Ruby - binding to libmysql
http://github.com/brianmario/mysql2
MIT License
2.25k stars 549 forks source link

Error installing mysql2 on Mac M1 pro (ventura) #1335

Open VictorOnwukwe opened 1 year ago

VictorOnwukwe commented 1 year ago

Hello. I am trying to install mysql2 on my macOS M1 pro (ventura 13.3.1) using the below command:

gem install mysql2 -v '0.5.5' -- --with-mysql-config=$(brew --prefix mysql)/bin/mysql_config --with-ldflags="-L$(brew --prefix zstd)/lib -L$(brew --prefix openssl)/lib" --with-cppflags=-I$(brew --prefix openssl)/include

as suggested here

I am getting the below error

Building native extensions with: '--with-mysql-config=/opt/homebrew/opt/mysql/bin/mysql_config --with-ldflags=-L/opt/homebrew/opt/zstd/lib -L/opt/homebrew/opt/openssl@3/lib --with-cppflags=-I/opt/homebrew/opt/openssl@3/include'
This could take a while...
ERROR:  Error installing mysql2:
    ERROR: Failed to build gem native extension.

    current directory: /Users/victoronwukwe/.rvm/gems/ruby-3.2.2/gems/mysql2-0.5.5/ext/mysql2
/Users/victoronwukwe/.rvm/rubies/ruby-3.2.2/bin/ruby extconf.rb --with-mysql-config\=/opt/homebrew/opt/mysql/bin/mysql_config --with-ldflags\=-L/opt/homebrew/opt/zstd/lib\ -L/opt/homebrew/opt/openssl@3/lib --with-cppflags\=-I/opt/homebrew/opt/openssl@3/include
checking for rb_absint_size()... yes
checking for rb_absint_singlebit_p()... yes
checking for rb_gc_mark_movable()... yes
checking for rb_wait_for_single_fd()... yes
checking for rb_enc_interned_str() in ruby.h... yes
-----
Cannot find library dir(s) /usr/share/rvm/usr/lib
-----
*** 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
    --without-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/victoronwukwe/.rvm/rubies/ruby-3.2.2/bin/$(RUBY_BASE_NAME)
    --with-openssl-dir
    --with-openssl-dir
    --with-openssl-include
    --without-openssl-include=${openssl-dir}/include
    --with-openssl-lib
    --without-openssl-lib=${openssl-dir}/lib

To see why this extension failed to compile, please check the mkmf.log which can be found here:

  /Users/victoronwukwe/.rvm/gems/ruby-3.2.2/extensions/arm64-darwin-22/3.2.0/mysql2-0.5.5/mkmf.log

extconf failed, exit code 1

Gem files will remain installed in /Users/victoronwukwe/.rvm/gems/ruby-3.2.2/gems/mysql2-0.5.5 for inspection.
Results logged to /Users/victoronwukwe/.rvm/gems/ruby-3.2.2/extensions/arm64-darwin-22/3.2.0/mysql2-0.5.5/gem_make.out

Any suggestion will be appreciated. I'll be happy to provide any further required information.

VictorOnwukwe commented 1 year ago

After trying just about every proposed solution by both humans and AI, I eventually resolved this issue by uninstalling ruby and rvm completely and then reinstalling. I still don't know what caused the issue. But this was my fix. Just leaving this out here.

sreenak commented 9 months ago

@VictorOnwukwe Could you please share here which tutorial you followed to install all, even I have the same issue, struggling with it.

VictorOnwukwe commented 8 months ago

@sreenak I can't recall the tutorial I followed, but I stored the command that worked. Here it is:

gem install mysql2 -v ‘0.5.5’ -- --with-ldflags=-L/opt/homebrew/opt/openssl@3/lib --with-cppflags=-I/opt/homebrew/opt/openssl@3/include

trevorh commented 6 months ago

Just in case the other commands don't work. This is what worked for me.

gem uninstall mysql2

bundle config --local build.mysql2 -- --with-mysql-config=$(brew --prefix mysql)/bin/mysql_config --with-ldflags="-L$(brew --prefix zstd)/lib -L$(brew --prefix openssl)/lib" --with-cppflags=-I$(brew --prefix openssl)/include --with-cflags="-Wno-error=implicit-function-declaration"

bundle install