What do I need to install mysql gem on Mac OS X ? I\'m getting error \"failed to build native extensions\".
I installed MySQL with Homebrew and I had to use this to finally be able to upgrade the gem:
gem install mysql2 -- --with-mysql-dir=/usr/local/opt/mysql/
if you already have MySQL server running elsewhere on the network and would like to still install the gem without having to install MySQL try the following
brew install mysql-connector-c
followed by
gem install mysql
I'm using Mac OS X Mountain Lion, and installed MySQL with DMG.
gem install do_mysql -- \ --with-mysql-dir=/usr/local/mysql --with-mysql-lib=/usr/local/mysql/lib --with-mysql-include=/usr/local/mysql/include
and
sudo ln -s /usr/local/mysql/lib/libmysqlclient.18.dylib /usr/lib/libmysqlclient.18.dylib
This works for me ;)
Install MySQL first, either by using binary or Homebrew.
Then:
gem install mysql2
Or:
gem install ruby-mysql
Just pick one and you are good to go.
Edit
In case you upgraded to MySQL version 5.6.12 on OS X, mysql2 will fail to compile. Solution is to downgrade MySQL as described here: https://stackoverflow.com/a/17252887/45254
Edit2
In case you don't want to have mysql installed (maybe you use docker to manage your services) but do want to use mysql2 gem, you can instead install mysql-connector-c
(using homebrew).