[오류 해결::Ruby] Ruby 3.0.1 mysql2 설치 오류
오류 발생
Ruby 3.0.1버전으로 Rails 7을 사용하는 중 bundle install
실행 시 mysql2
를 설치하는 과정에서 오류가 발생했습니다.
iksflow@iksflow archive % bundle install
Fetching gem metadata from https://rubygems.org/...........
Resolving dependencies.......
Using rake 13.0.6
Using concurrent-ruby 1.1.9
Using minitest 5.15.0
Using builder 3.2.4
Using erubi 1.10.0
Using racc 1.6.0
Using crass 1.0.6
Using rack 2.2.3
Using nio4r 2.5.8
Using websocket-extensions 0.1.5
Using marcel 1.0.2
Using mini_mime 1.1.2
Using digest 3.1.0
Using io-wait 0.2.1
Using timeout 0.2.0
Using strscan 3.0.1
Using msgpack 1.4.4
Using bundler 2.2.15
Using io-console 0.5.11
Using i18n 1.9.1
Using thor 1.2.1
Using zeitwerk 2.5.4
Fetching mysql2 0.5.3
Using tzinfo 2.0.4
Using nokogiri 1.13.1 (x86_64-darwin)
Using rack-test 1.1.0
Using activesupport 7.0.1
Using websocket-driver 0.7.5
Using mail 2.7.1
Using rails-dom-testing 2.0.3
Using loofah 2.13.0
Using globalid 1.0.0
Using rails-html-sanitizer 1.4.2
Using net-protocol 0.1.2
Using activemodel 7.0.1
Using actionview 7.0.1
Using activerecord 7.0.1
Using puma 5.6.1
Using actionpack 7.0.1
Using activejob 7.0.1
Using actioncable 7.0.1
Using activestorage 7.0.1
Using net-smtp 0.3.1
Using actiontext 7.0.1
Using method_source 1.0.0
Using reline 0.3.1
Using railties 7.0.1
Using irb 1.4.1
Using bootsnap 1.10.3
Using debug 1.4.0
Using net-imap 0.2.3
Using net-pop 0.1.1
Using actionmailbox 7.0.1
Using actionmailer 7.0.1
Using rails 7.0.1
Installing mysql2 0.5.3 with native extensions
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.
current directory: /Users/iksflow/.asdf/installs/ruby/3.0.1/lib/ruby/gems/3.0.0/gems/mysql2-0.5.3/ext/mysql2
/Users/iksflow/.asdf/installs/ruby/3.0.1/bin/ruby -I /Users/iksflow/.asdf/installs/ruby/3.0.1/lib/ruby/3.0.0 -r ./siteconf20220202-6926-rbouig.rb extconf.rb
checking for rb_absint_size()... yes
checking for rb_absint_singlebit_p()... yes
checking for rb_wait_for_single_fd()... yes
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers. Check the mkmf.log file for more details. You may
need configuration options.
Provided configuration options:
--with-opt-dir
--without-opt-dir
--with-opt-include
--without-opt-include=${opt-dir}/include
--with-opt-lib
--without-opt-lib=${opt-dir}/lib
--with-make-prog
--without-make-prog
--srcdir=.
--curdir
--ruby=/Users/iksflow/.asdf/installs/ruby/3.0.1/bin/$(RUBY_BASE_NAME)
--with-mysql-dir
--without-mysql-dir
--with-mysql-include
--without-mysql-include=${mysql-dir}/include
--with-mysql-lib
--without-mysql-lib=${mysql-dir}/lib
--with-mysql-config
--without-mysql-config
--with-mysqlclient-dir
--without-mysqlclient-dir
--with-mysqlclient-include
--without-mysqlclient-include=${mysqlclient-dir}/include
--with-mysqlclient-lib
--without-mysqlclient-lib=${mysqlclient-dir}/lib
--with-mysqlclientlib
--without-mysqlclientlib
/Users/iksflow/.asdf/installs/ruby/3.0.1/lib/ruby/3.0.0/mkmf.rb:1050:in `block in find_library': undefined method `split' for nil:NilClass (NoMethodError)
from /Users/iksflow/.asdf/installs/ruby/3.0.1/lib/ruby/3.0.0/mkmf.rb:1050:in `collect'
from /Users/iksflow/.asdf/installs/ruby/3.0.1/lib/ruby/3.0.0/mkmf.rb:1050:in `find_library'
from extconf.rb:87:in `<main>'
To see why this extension failed to compile, please check the mkmf.log which can be found here:
/Users/iksflow/.asdf/installs/ruby/3.0.1/lib/ruby/gems/3.0.0/extensions/x86_64-darwin-20/3.0.0/mysql2-0.5.3/mkmf.log
extconf failed, exit code 1
Gem files will remain installed in /Users/iksflow/.asdf/installs/ruby/3.0.1/lib/ruby/gems/3.0.0/gems/mysql2-0.5.3 for inspection.
Results logged to /Users/iksflow/.asdf/installs/ruby/3.0.1/lib/ruby/gems/3.0.0/extensions/x86_64-darwin-20/3.0.0/mysql2-0.5.3/gem_make.out
An error occurred while installing mysql2 (0.5.3), and Bundler cannot continue.
Make sure that `gem install mysql2 -v '0.5.3' --source 'https://rubygems.org/'` succeeds before bundling.
In Gemfile:
mysql2
해결 방법
mysql이 설치된 경로를 옵션으로 설정해야합니다.
저는 Homebrew
를 통해 설치한 8.0.28
버전의 경로로 설정했습니다.
본인의 mysql설치 경로를 확인하고 해당 경로로 옵션을 설정해서 gem install
을 실행합니다.
주의할 점은 Mac이 Intel칩이냐 M1칩이냐에 따라 Homebrew의 패키지 설치경로가 달라지므로 본인의 Mac에 해당하는 코드를 실행해야 합니다.
# Intel칩 Mac
gem install mysql2 -- \
--with-mysql-lib=/usr/local/Cellar/mysql/8.0.28/lib \
--with-mysql-dir=/usr/local/Cellar/mysql/8.0.28/ \
--with-mysql-config=/usr/local/Cellar/mysql/8.0.28/bin/mysql_config \
--with-mysql-include=/usr/local/Cellar/mysql/8.0.28/include
# M1칩 Mac
gem install mysql2 -- \
--with-mysql-lib=/opt/homebrew/Cellar/mysql/8.0.28/lib \
--with-mysql-dir=/opt/homebrew/Cellar/mysql/8.0.28/ \
--with-mysql-config=/opt/homebrew/Cellar/mysql/8.0.28/bin/mysql_config \
--with-mysql-include=/opt/homebrew/Cellar/mysql/8.0.28/include