Skip to content

Instantly share code, notes, and snippets.

@runlevel5
Last active July 3, 2019 06:11
Show Gist options
  • Save runlevel5/90d3369ad1daa4ab4acd054bfee168df to your computer and use it in GitHub Desktop.
Save runlevel5/90d3369ad1daa4ab4acd054bfee168df to your computer and use it in GitHub Desktop.
How to bundler to bundle install mysql2 gem

So if you have ever run into failing to install mysql2 gem with bundler, here is a quick way to resolve it:

  1. Install MySQL with dev headers
  2. Configure bundler mysql2.build option: bundle config build.mysql2 --with-mysql-dir=<path_to_mysql_folder>
  3. bundle install

If you run into issue like this (which is likely if your MySQL does not get installed into /usr/local/mysql on macOS)

/Users/tle/.asdf/installs/ruby/2.3.5/lib/ruby/gems/2.3.0/gems/mysql2-0.5.2/lib/mysql2.rb:33:in `require':LoadError: dlopen(/Users/tle/.asdf/installs/ruby/2.3.5/lib/ruby/gems/2.3.0/gems/mysql2-0.5.2/lib/mysql2/mysql2.bundle, 9): Library not loaded: /usr/local/mysql/lib/libmysqlclient.20.dylib
  Referenced from: /Users/tle/.asdf/installs/ruby/2.3.5/lib/ruby/gems/2.3.0/gems/mysql2-0.5.2/lib/mysql2/mysql2.bundle

You can resolve it by creating a symlink to that libmysqlclient.20.dylib:

sudo mkdir -p /usr/local/mysql/lib
sudo ln -sf /path/to/mysql/lib/libmysqlclient.20.dylib /usr/local/mysql/lib/libmysqlclient.20.dylib
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment