Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Install mysql2 on MacOS Mojave

Problem

Installing mysql2 gem errors on MacOS Mojave.

Solution

Make sure openssl is installed on Mac via Homebrew.

brew install openssl

Install mysql2 gem.

gem install mysql2 -v '0.5.2' -- --with-ldflags=-L/usr/local/opt/openssl/lib --with-cppflags=-I/usr/local/opt/openssl/include
@repoles

This comment has been minimized.

Copy link

repoles commented Oct 4, 2018

Thanks, man!

@swaincreates

This comment has been minimized.

Copy link

swaincreates commented Oct 5, 2018

Heroic

@vincepreziose

This comment has been minimized.

Copy link

vincepreziose commented Oct 13, 2018

Yaasss!

@mgoggin

This comment has been minimized.

Copy link

mgoggin commented Oct 18, 2018

If you came here because you're trying to bundle your project into a specific directory and the gem won't build, you can tell bundler to use these build flags when it installs the gem.

bundle config build.mysql2 --with-ldflags=-L/usr/local/opt/openssl/lib --with-cppflags=-I/usr/local/opt/openssl/include
bundle install --path .bundle
@mckomo

This comment has been minimized.

Copy link

mckomo commented Nov 28, 2018

Thanks!

@nagative

This comment has been minimized.

Copy link

nagative commented Dec 16, 2018

Thank you so much! You were a big help!

@s1monw1

This comment has been minimized.

Copy link

s1monw1 commented Dec 28, 2018

took me an hour until I finally found your solution, thanks!

@rslhdyt

This comment has been minimized.

Copy link

rslhdyt commented Jan 18, 2019

save my life

@rikas

This comment has been minimized.

Copy link

rikas commented Jan 20, 2019

I still get this error:

cannot load such file -- mysql2/mysql2

when trying to use mysql2 on Rails (5.2.2)

@Stratus3D

This comment has been minimized.

Copy link

Stratus3D commented Jan 23, 2019

Works on my machine!

@tr00gle

This comment has been minimized.

Copy link

tr00gle commented Jan 24, 2019

Just found this, and it was immensely helpful. How did you reach this solution?

@giuseb

This comment has been minimized.

Copy link

giuseb commented Jan 29, 2019

excellent, thanks!

@bearpatrol64

This comment has been minimized.

Copy link

bearpatrol64 commented Jan 31, 2019

Hurray!!! That did it!
Thank you!

@rbercam

This comment has been minimized.

Copy link

rbercam commented Feb 5, 2019

Thank you!

@katherine-boost

This comment has been minimized.

Copy link

katherine-boost commented Feb 11, 2019

Much appreciated!

@FlavioLudi

This comment has been minimized.

Copy link

FlavioLudi commented Feb 12, 2019

Thanks!

@kabaken

This comment has been minimized.

Copy link

kabaken commented Feb 13, 2019

ありがとう!

@samholst

This comment has been minimized.

Copy link

samholst commented Feb 20, 2019

You the man!

@CiTroNaK

This comment has been minimized.

Copy link

CiTroNaK commented Feb 21, 2019

Thanks!

@bthibault

This comment has been minimized.

Copy link

bthibault commented Feb 22, 2019

🥇

@fschueller

This comment has been minimized.

Copy link

fschueller commented Mar 12, 2019

Thank you, just saved me quite some time!

@IanPurdom

This comment has been minimized.

Copy link

IanPurdom commented Mar 26, 2019

Thanks a lot man! I was seriously getting crazy!

@oseiyoke

This comment has been minimized.

Copy link

oseiyoke commented Mar 29, 2019

Thanks a lot man. Been on it for an hour!!

@njt1982

This comment has been minimized.

Copy link

njt1982 commented Mar 29, 2019

I have this in ~/.bundle/config:

BUNDLE_BUILD__NOKOGIRI: "--use-system-libraries --with-xml2-include=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/libxml2/"
BUNDLE_BUILD__MYSQL2: "--with-ldflags=-L/usr/local/opt/openssl@1.1/lib --with-cppflags=-I/usr/local/opt/openssl@1.1/include"
@kule

This comment has been minimized.

Copy link

kule commented Apr 2, 2019

This worked for me:

bundle config build.mysql2 --with-opt-dir=/usr/local/opt/openssl

@Bozazitz

This comment has been minimized.

Copy link

Bozazitz commented Apr 2, 2019

thanks bro, saved me loads of time

@SidOfc

This comment has been minimized.

Copy link

SidOfc commented Apr 4, 2019

I got here because I got don't know how to set rpath on your system error initially. Upon googling you'll reach this SO thread which only details either installing / reinstalling openssl but since I already did this and all other configuration options mentioned were outdated for me, this wasn't very useful. Only after fiddling with many different configuration options, none of which worked, this actually got it to work for me.

It really does suck that the combination of mysql+brew+macos seems to break with every OS update, though :(

macOS 10.14.3
fish 3.0.1
openssl 1.0.2r

With all that being said, thanks a lot, you saved me some good amount of time as well!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.