mysql2: `ld: library not found for -lssl` after Mac OS Sierra upgrade
After upgrading to Sierra. Confirmed that OpenSSL and LibreSSL are installed through Homebrew. I’m continuing to troubleshoot.
gem install mysql2
Building native extensions. This could take a while...
ERROR: Error installing mysql2:
ERROR: Failed to build gem native extension.
/Users/frank/.rbenv/versions/2.2.4/bin/ruby -r ./siteconf20161017-40878-1pj8mbn.rb extconf.rb
checking for ruby/thread.h... yes
checking for rb_thread_call_without_gvl() in ruby/thread.h... yes
checking for rb_thread_blocking_region()... no
checking for rb_wait_for_single_fd()... yes
checking for rb_hash_dup()... yes
checking for rb_intern3()... yes
-----
Using mysql_config at /usr/local/bin/mysql_config
-----
checking for mysql.h... yes
checking for errmsg.h... yes
checking for mysqld_error.h... yes
-----
Don't know how to set rpath on your system, if MySQL libraries are not in path mysql2 may not load
-----
-----
Setting libpath to /usr/local/Cellar/mariadb/10.1.18/lib
-----
creating Makefile
make "DESTDIR=" clean
make "DESTDIR="
compiling client.c
compiling infile.c
compiling mysql2_ext.c
compiling result.c
compiling statement.c
linking shared-object mysql2/mysql2.bundle
ld: library not found for -lssl
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [mysql2.bundle] Error 1
make failed, exit code 2
Gem files will remain installed in /Users/frank/.rbenv/versions/2.2.4/lib/ruby/gems/2.2.0/gems/mysql2-0.4.4 for inspection.
Results logged to /Users/frank/.rbenv/versions/2.2.4/lib/ruby/gems/2.2.0/extensions/x86_64-darwin-16/2.2.0-static/mysql2-0.4.4/gem_make.out
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Reactions: 22
- Comments: 70 (2 by maintainers)
Links to this issue
- ruby on rails - An error occurred while installing mysql2 (0.4.8), and Bundler cannot continue - Stack Overflow
- ruby on rails - mysql2 gem in gem list but getting project can not find gem - Stack Overflow
- mysql - Error when trying to install app with mysql2 gem - Stack Overflow
- linux - mysql_config not found when installing mysqldb python interface - Stack Overflow
Commits related to this issue
- try xcode-select --install per https://github.com/brianmario/mysql2/issues/795#issuecomment-254324527 — committed to r-dbi/RMariaDB by krlmlr 7 years ago
- rails newしたの. - rails new rpg_battle_simulator --database=mysql --skip-action-mailer --skip-active-storage --skip-action-cable --skip-test - cd rpg_battle_simulator = bundle config --global build.mys... — committed to hideyuki-matsuyama/rpg_battle_simulator by hideyuki-matsuyama 5 years ago
- Tell libetpan where to find libssl on Sierra+ https://github.com/brianmario/mysql2/issues/795 — committed to Foundry376/Mailspring-Sync by bengotow 5 years ago
- Tell libetpan where to find libssl on Sierra+ https://github.com/brianmario/mysql2/issues/795 — committed to Foundry376/Mailspring-Sync by bengotow 5 years ago
- Add new env variable Add LIBRARY_PATH for openssl so that mysql2 gem will compile and run properly. See more details at https://github.com/brianmario/mysql2/issues/795#issuecomment-430312000 — committed to btoone/dotfiles by btoone 4 years ago
Step 1.
brew install openssl
Step 2.
export LIBRARY_PATH=$LIBRARY_PATH:/usr/local/opt/openssl/lib/
Changing the
$LIBRARY_PATH
did not work for me, but this did:The solution was:
xcode-select --install
I really wish XCode would update without removing the command line tools every time without notice.
To fix for a manual gem install:
To fix for all bundle installs:
Thank you @dibowei I will never get those couple of hours back but you definitely saved me a few more!
Thank you very much @dibowei, same thing happened in OS X 10.14 Mojave, this fixed it.
This error occurred for me trying to install
mysql2
gem withgem install mysql2
(posting this so hopefully future poor souls googling
mysql2
install errors will see this…)Hm this didn’t work for me still seeing same error
You can also try this on macOS
This thread ranks highly in Google. For other people arriving here after trying to get mysql2 gem going on OS X 10.14 Mojave, this did it for me. Stuck it in
.bash_profile
as well.I had problem installing psycopg2 with error message
on macos Big Sur devBeta 2, xcode 12 Beta and command line tools all installed.
solved the problem right away.
I encountered this error when using
pip install MySQL-python
. Commenting here as the above solution worked (again for googlers)If you’re using openssl installed by homebrew natively on Apple Silicon,
openssl@1.1/lib
no longer lives at/usr/local/opt
. For an architecture independent way of referring to openssl, try:export LIBRARY_PATH=$LIBRARY_PATH:$(brew --prefix openssl@1.1)/lib/
This saved me hours, Thanks ^_^
I love you
I have command line tools installed as well as Xcode 9. I tried reinstalling command line tools by
mv /Library/Developer/CommandLineTools /Library/Developer/CommandLineTools.bak
and runningxcode-select --install
again. I also tried a restart as suggested above, with no luck. Is there a way to tell it where openssl is installed?Update: I got it working after doing
rbenv local 2.4.0
. Not sure why this worked.MacOS Monterey
Check your installed mysql version(i’m using 8.0.28_1)
ls /opt/homebrew/Cellar/mysql
Change the bundle.mysql2 config (change ‘8.0.28_1’ for the mysql installed version)
bundle config build.mysql2 -- \ --with-mysql-lib=/opt/homebrew/Cellar/mysql/8.0.28_1/lib \ --with-mysql-dir=/opt/homebrew/Cellar/mysql/8.0.28_1 \ --with-mysql-config=/opt/homebrew/Cellar/mysql/8.0.28_1/bin/mysql_config \ --with-mysql-include=/opt/homebrew/Cellar/mysql/8.0.28_1/include
Run:
bundle install
@dibowei Thanks for the fix. It worked like a charm. I can’t believe 2 years later and this this still needs to be done by hand.
hit this on catalina with xcode 11.2 and had to make a slight tweak on previous solutions to use openssl@1.1
bundle config build.mysql2 --with-opt-dir=“$(brew --prefix openssl@1.1)”
when i run
xcode-select --install
i get error xcode-select: error: command line tools are already installed, use “Software Update” to install updatesexactly same error as @mastahyeti
Even after making a:
@dibowei’s solution worked but with modified for Apple M1
export LIBRARY_PATH=$LIBRARY_PATH:/opt/homebrew/Cellar/openssl@1.1/1.1.1k/lib
Thanks soooooo much 👍
This also worked for Python’s
mysqlclient
:Oh, glad you found it. Yeah, that’s annoying every time. Maybe a specific check is in order? I wonder if
xcode-select --print-path
fails after an upgrade.Thanks @profx, your tips solved similar for me on Mojave 🎉
Had to do the below after a
xcode-select --install
_From https://stackoverflow.com/a/56228387/946175 and https://stackoverflow.com/a/55732339/946175_
This saved my day!
if anyone is facing issue while installing
mysqlclient
in mac. Use this command.LDFLAGS=-L/usr/local/opt/openssl/lib pip3 install mysqlclient
No luck tried all the above, below are the details:
Mojave 10.14.3
Might be for someone
brew reinstall openssl
. After like 12 hours of searching worked for me.Same for me on Mojave, but this solution https://github.com/brianmario/mysql2/issues/795#issuecomment-433219176 worked fine
In my case, I was having trouble installing
MySQL-python
onpython 2.7
withopenssl@1.1
. Taking cues from the above, I realized that the symlinks were not being passed properly. So I proceeded to link openssl manuallyThis failed with a denied error, but prompted me the right steps
I then passed the correct linker flags and it worked (later updated my bashrc)
Later, set the flags in your bash profiles. God damn, clang/openssl on Mac.
I faced the same issue in MAC OS Catalina. A slight variation of the above solutions/workarounds helped me solve the issue: Step 1:
brew install openssl
(this installs openssl@1.1) Step 2:export LIBRARY_PATH=$LIBRARY_PATH:/usr/local/opt/openssl\@1.1/lib/
I encountered this error while installing psycopg2 on Mojave into a virtual Python environment created with pyenv. I already had Xcode and the Command Line Tools installed, and checked that using the xcode-select --install command, xcode-select -p, and echo $?, which returned a 0, indicating they were installed.
It turns out Mojave and/or Xcode 10 does not create a /usr/include directory, which psycopg2 needs to install (other “legacy” apps may need this, too, as indicated in Apple’s developer forum. I posted about it here https://stackoverflow.com/questions/26288042/error-installing-psycopg2-library-not-found-for-lssl/57746760#5774676, but found the solution here: https://stackoverflow.com/questions/34617452/how-to-update-xcode-from-command-line, which references https://forums.developer.apple.com/thread/104296.
A combination of this and running
pip install MySQL-python
seperately instead ofpip install -r requirements.txt
worked for me 🙏works for me on Mojave 😉 many thanks
I had upgraded from Sierra to High Sierra a couple of weeks back. I received this error when I tried to install mysqlclient. After running
xcode-select --install
the problem disappeared. Thank you!This worked for me. Thanks!
This solution deserves its own documentation repo, with different fixes for the platforms, along with PRs to fix them! 😄
Also helped me, many thanks!
I didn’t realize brew was so buggy. I brew installed plantuml and suddenly couldn’t get my existing rails application to work. I did
bundle pristine --all
as mentioned https://stackoverflow.com/a/59438200, and it showed a mysql2 error, which led me here. It also broke vim:Versions: MacOS 10.14.6 gem install mysql2 -v ‘0.4.10’
Thanks @rietta, still works in 2020. Kudos 👍
Try:
Happy to report @dibowei that even almost two years later, this suggestion helped! Particularly Step 2. Thanks
This works for me!
Thanks @dibowei, that worked!
Posting this comment just to share my experience and help other people. I fixed this error by uninstalling and installing mysql formula from homebrew, I suspect the error was originated by updating to macOS Mojave. My old mysql version was 5.7.22 and after reinstalling mysql it was 8.0.13, so had to install an older version mysql@5.7 and then brew link.
I had this error while trying to install the
MySQL-python
connector. Runningxcode-select --install
solved that immediately.Thanks a lot for the info