Error when trying to install app with mysql2 gem
Solution 1
The error log says:
ld: library not found for -lssl
So, you need to install libssl
:
brew install openssl
As it was pointed out in comments, there might be a need to export the path to the library.
export LIBRARY_PATH=$LIBRARY_PATH:/usr/local/opt/openssl/lib/
Solution 2
For anybody still experiencing the issue:
When you install openssl via brew, you should get the following message:
Apple has deprecated use of OpenSSL in favor of its own TLS and crypto libraries
Generally there are no consequences of this for you. If you build your own software and it requires this formula, you'll need to add to your build variables:
LDFLAGS: -L/usr/local/opt/openssl/lib
CPPFLAGS: -I/usr/local/opt/openssl/include
PKG_CONFIG_PATH: /usr/local/opt/openssl/lib/pkgconfig
You can set these build flags (for the local application) by running the following:
bundle config --local build.mysql2 "--with-ldflags=-L/usr/local/opt/openssl/lib --with-cppflags=-I/usr/local/opt/openssl/include"
This worked for me.
See bundler's documentation for more information.
Solution 3
Try this:
gem install mysql2 -v '0.5.2' -- --with-ldflags=-L/usr/local/opt/openssl/lib --with-cppflags=-I/usr/local/opt/openssl/include
(Update version as appropriate)
Solution 4
The solution for me was to install the Xcode Command Line Tools.
I had recently updated Xcode through the Mac App Store, and every time I do that, I've found that I have to reinstall the Command Line Tools again.
xcode-select --install
Solution 5
Based on the solution here
brew install openssl
export LIBRARY_PATH=$LIBRARY_PATH:/usr/local/opt/openssl/lib/
solved the problem.
zenvelope
Updated on July 08, 2022Comments
-
zenvelope almost 2 years
Im trying to install an open source rails 3.2.21 application that uses the
mysql2
gem, but when i try and run thebundle
commant I get the following error:Fetching: mysql2-0.3.18.gem (100%) Building native extensions. This could take a while... p ERROR: Error installing mysql2: ERROR: Failed to build gem native extension. /Users/my_username/.rvm/rubies/ruby-2.1.2/bin/ruby -r ./siteconf20150614-72129-orqsb7.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()... yes 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/mysql/5.6.25/lib ----- creating Makefile make "DESTDIR=" clean make "DESTDIR=" compiling client.c compiling infile.c compiling mysql2_ext.c compiling result.c linking shared-object mysql2/mysql2.bundle ld: warning: directory not found for option '-L/Users/travis/.sm/pkg/active/lib' 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/my_username/.rvm/rubies/ruby-2.1.2/lib/ruby/gems/2.1.0/gems/mysql2-0.3.18 for inspection. Results logged to /Users/my_username/.rvm/rubies/ruby-2.1.2/lib/ruby/gems/2.1.0/extensions/x86
I tried uninstalling every version of
mysql
I installed via homebrew and reinstalling them, like so:brew uninstall --force mysql && brew install mysql
Then running:
sudo gem install mysql2
As suggested by a number of similar questions asked on here, but it still results in the same error as above.
Please could someone offer guidance on how to get this up and running?
-
niels over 7 yearsIf you just want to use
gem install
, the following works:gem install mysql2 -v '0.3.21' -- --with-ldflags=-L/usr/local/opt/openssl/lib --with-cppflags=-I/usr/local/opt/openssl/include
-
the12 over 7 years^^^ @niels that should be the answer... Alessandro's does not work on Sierra ("Warning: Refusing to link: open ssl..." --> something to do with the deprecated system of openssl)
-
Admin over 7 years@the12 niels's solution is for
gem install
, mine is forbundle install
. What issue are you experiencing exactly, can you post the error? The solution I posted still works for me. -
vergenzt about 7 yearsI started from trying to
bundle install
for a repo that depends on mysql. @AlessandroBerardi's solution did not work for me; @niels' did. :/ -
jpayne over 5 yearsThe bundle config command didn't work for me (although it has in the past). The 'gem install' command of niels did work (hours later). The bundle config command failed because it looks like it passed --with-ldflags and --with-cppflags as arguments to clang producing clang: error: unsupported option '--with-cppflags=-I/usr/local/opt/openssl/include'
-
TehJabbit almost 5 yearsGiven that the SSL library was not found this is the correct approach and worked fine for me.
-
A moskal escaping from Russia almost 5 years@the12 niels' comment is already an answer stackoverflow.com/a/55186244/5025116
-
Touseef Murtaza almost 5 yearsFirst install
brew install openssl
thengem install mysql2 -v '0.4.10' -- --with-ldflags=-L/usr/local/opt/openssl/lib --with-cppflags=-I/usr/local/opt/openssl/include
worked for me, Thanks! -
Gilg Him almost 5 yearsThat was not enough, One need to export it afterward like this:
export LIBRARY_PATH=$LIBRARY_PATH:/usr/local/opt/openssl/lib/
-
Xavier Shay over 4 years--with-cppflags appears to break on latest OSX. I believe it can be omitted.
bundle config --local build.mysql2 "--with-ldflags=-L/usr/local/opt/openssl/lib"
-
Jared over 4 years@TouseefMurtaza your answer worked for me - thank you!
-
Yakob Ubaidi over 4 yearsthe
export
really helps. even with existing openssl the path is missing. -
Abhi about 4 yearsexport LIBRARY_PATH=$LIBRARY_PATH:/usr/local/opt/openssl/lib/` Works for me after a long try. Thx!!
-
Naga Hemanth over 3 yearsThanks! Really helpful
-
Jeremy Ferguson almost 3 yearsThis is the way.
-
devjme over 2 yearsYes just use the bundle config without the cppflags option and it works on big sir see xavier Shay's comment above
-
Joshua Pinter over 2 yearsThis was the ONLY thing that worked for me on the M1 Mac Mini. Thank you for posting!
-
Paul Trott over 2 yearsThanks for this post!
-
Andy Ray over 2 yearsWhy does Ruby suffer from this problem so much worse than any other ecosystems? Why do Gem developers not put effort into making good install processes?
-
Aleksei Matiushkin over 2 years@AndyRay This is absolutely not ruby to blame, but MacOS. This OS has never been suitable for development.
-
brentonstrine over 2 yearsThat third line to install
mysql2
generates this error on an M1 Mac w/ Monterey:linking shared-object mysql2/mysql2.bundle ld: warning: directory not found for option '-L/opt/homebrew/Cellar/zstd/1.5.0/lib' ld: library not found for -lzstd 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/u/.gem/ruby/2.6.5/gems/mysql2-0.5.3 for inspection. Results logged to /Users/u/.gem/ruby/2.6.5/extensions/-darwin-21/2.6.0-static/mysql2-0.5.3/gem_make.out
-
Israel about 2 yearsThis is the solution for Mac M1 pro
-
rakesh kumar almost 2 yearswonderful its work on Mac M1 chip..