LoginSignup
6
6

More than 5 years have passed since last update.

rails mysql2のインストール時のエラー

Last updated at Posted at 2019-02-18

gemのmysql2をインストールする際にハマったのでメモ

エラーログ

Fetching mysql2 0.3.21
Installing mysql2 0.3.21 with native extensions
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

    current directory: /path/to/vendor/bundle/ruby/2.4.0/gems/mysql2-0.3.21/ext/mysql2
/path/to/.rbenv/versions/2.4.1/bin/ruby -I /path/to/.rbenv/versions/2.4.1/lib/ruby/site_ruby/2.4.0 -r ./siteconf20190218-87873-15epx9f.rb extconf.rb
--with-cppflags\=-I/usr/local/opt/openssl/include
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/opt/mysql@5.7/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/opt/mysql@5.7/lib
-----
creating Makefile

current directory: /path/to/vendor/bundle/ruby/2.4.0/gems/mysql2-0.3.21/ext/mysql2
make "DESTDIR=" clean

current directory: /path/to/vendor/bundle/ruby/2.4.0/gems/mysql2-0.3.21/ext/mysql2
make "DESTDIR="
compiling client.c
compiling infile.c
compiling mysql2_ext.c
compiling result.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 /path/to/vendor/bundle/ruby/2.4.0/gems/mysql2-0.3.21 for inspection.
Results logged to /path/to/vendor/bundle/ruby/2.4.0/extensions/x86_64-darwin-18/2.4.0-static/mysql2-0.3.21/gem_make.out

An error occurred while installing mysql2 (0.3.21), and Bundler cannot continue.
Make sure that `gem install mysql2 -v '0.3.21' --source 'https://rubygems.org/'` succeeds before bundling.

In Gemfile:
  mysql2

パスが通っていないのが原因

bundle config --local build.mysql2 "--with-ldflags=-L/usr/local/opt/openssl/lib"
6
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
6