gem install mysql2
I’ve come across this error several times throughout my development career so I figured it was finally time to write it down.
Scenario
Whenever I try to install certain versions of the mysql2
gem in a Ruby on Rails application, I get the following error:
Gem::Ext::BuildError: ERROR: Failed to build gem native extension...make "DESTDIR="compiling client.ccompiling infile.ccompiling mysql2_ext.ccompiling result.ccompiling statement.clinking shared-object mysql2/mysql2.bundleld: library not found for -lsslclang: error: linker command failed with exit code 1 (use -v to see invocation)make: *** [mysql2.bundle] Error 1 make failed, exit code 2 An error occurred while installing mysql2 (0.5.2), and Bundler cannot continue.Make sure that `gem install mysql2 -v '0.5.2'` succeeds before bundling.
Solution
In order to fix this issue on macOS, first make sure that you have cmake
installed.
brew install cmake
Then you can install the gem via the following command:
gem install mysql2 -v '0.5.2' -- --with-ldflags=-L/usr/local/opt/openssl/lib --with-cppflags=-I/usr/local/opt/openssl/include
Hope this helps save someone some time!
![Andrew Mason's profile image](https://res.cloudinary.com/andrewmcodes/image/upload/w_128,c_fill,ar_1:1,g_auto,r_max/v1665648326/andrewm.codes/profile-gradient-1.png)
Hey, I'm Andrew 👋
I'm a senior product engineer at Podia, co-host of Remote Ruby and Ruby for All, and co-editor of Ruby Radar. You can explore my writing, learn more about me, or subscribe to my RSS feed.