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 11:58

So I ran into this similar issue and for me it turned out to be a wrong ruby version and incompatible MySQL version. I use ruby 2.3 on most of my projects but inherited a 2.1 project. Changing to rvm to use 2.1 got me a little further.

Then I found this: https://github.com/brianmario/mysql2/issues/603 that said you had to use mysql2 gem version greater than 0.3.17 with MySQL version 5.7

Updated gem to 0.3.17 and it fired right up. Hope this helps someone.

查看更多
Luminary・发光体
3楼-- · 2019-01-31 11:59

When you install openssl via brew, you should get the following message:

Apple has deprecated use of OpenSSL in favor of its own TLS and crypto libraries

Generally there are no consequences of this for you. If you build your own software and it requires this formula, you'll need to add to your build variables:

LDFLAGS: -L/usr/local/opt/openssl/lib
CPPFLAGS: -I/usr/local/opt/openssl/include
PKG_CONFIG_PATH: /usr/local/opt/openssl/lib/pkgconfig

You can set these build flags (for the local application) by running the following:

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

This worked for me.

See bundler's documentation for more information.

查看更多
神经病院院长
4楼-- · 2019-01-31 11:59

I have a problem like this. Hope this could be useful .

brew install mysql@5.6

brew link mysql@5.6 --force

bundle install

this answer help me !

查看更多
在下西门庆
5楼-- · 2019-01-31 12:00

Try installing xcode-select --install

查看更多
够拽才男人
6楼-- · 2019-01-31 12:01

I am here to share my fix, since the other answers didn't work.

For my environment, I need MySQL 5.6 so I had to use:

brew install mysql56 instead of brew install mysql

Bundle installing the mysql2 gem kept failing, until:

brew link mysql56

I also ran afterwards:

mysql.server start

The last step might be unnecessary, but just in case.

查看更多
欢心
7楼-- · 2019-01-31 12:05

I just had the same problem, tried all of the solutions listed above, then commenced to bang my head against they keyboard for a couple of hours.

I then thought to try and install/reinstall the Xcode Command Line Tools:

xcode-select --install

Once I did that the mysql2 gem installed w/ no problems. I hope that does the trick!

查看更多
登录 后发表回答