mysqlrubyosx-leopard

How to install MySQL gem on Mac OS X


What do I need to install mysql gem on Mac OS X ? I'm getting error "failed to build native extensions".


Solution

  • 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).