Can't install mysql2 gem on macOS Sierra

2019-01-31 11:35发布

I'm setting up my development environment in the new macOS Sierra .

First of all, I installed Rbenv, Ruby (2.3.1), Homebrew and so the latest version of MySQL (5.7.15).

$ brew install mysql
$ mysql.server start

Ok, MySQL was initialized. Time to install the mysql2 gem...

$ gem install mysql2 -- --with-mysql-config=/usr/local/Cellar/mysql/5.7.15/bin/mysql_config

But it didn't work.

8条回答
狗以群分
2楼-- · 2019-01-31 12:14

Almost the same scenario as @Caio Tarifa, Ruby 2.3.3, mysql 5.6 and mysql2. Tried on couple of solutions above and finally make it work with @kylekeesling's approach.

First, tried on solution 1 by @spickermann:

brew reinstall openssl && brew link openssl --force

Nothing happened, same error shown.

Second, tried on solution by @Alessandro Berardi:

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

This got different but more errors since it overwrite gem extension's config so all gem extension installation failed.

Finally, tried on @kylekeesling solution:

xcode-select --install

It fix mysql gem issue as well as nikogiri. Since I already intall Xcode, in my case it's reinstall the Xcode Command Line Tools.

查看更多
不美不萌又怎样
3楼-- · 2019-01-31 12:19

First, you should try 2 answer in here If you installed openssl but it still don't work. You should try to o refresh gems reference. A got the same issue and it worked for me.

gem source -r https://rubygems.org/

gem source -a https://rubygems.org/

查看更多
登录 后发表回答