Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot Install "mysql gem" on MacOS Sierra

I am trying to install the mysql2 gem for one of my rails projects but I am getting an error. I run this command:

gem install mysql2

The error says:

ld: library not found for -lssl

However when I run:

brew install openssl

I get (which proves that I have the -lssl library):

Error: openssl-1.0.2f already installed
To install this version, first `brew unlink openssl`

And alternatively when I run (which proves I have mysql on my machine):

brew install mysql 

I get:

Error: mysql-5.7.10 already installed
To install this version, first `brew unlink mysql`

Very lost and would love to solve this, thank you in advance. I am running brew version 1.0.4.

like image 413
Robert Saunders Avatar asked Oct 29 '22 19:10

Robert Saunders


1 Answers

I am having the same problem on Mac OS Mojave.

The following worked for me. First – very important – I ran xcode and discovered it needed to install some crap again. Then I did

brew reinstall openssl 
gem install mysql2 -v '0.4.5' -- --with-ldflags=-L/usr/local/opt/openssl/lib --with-cppflags=-I/usr/local/opt/openssl/include
bundle install

The second line is based on the answer here.

like image 82
Will Avatar answered Nov 13 '22 00:11

Will