LoginSignup
67
38

More than 5 years have passed since last update.

[MacOS Mojave]mysql2のbundle installに失敗してハマった件

Posted at

Railsアプリを作る際、mysql指定でやってみたら思いの外ハマってしまったので、解決した時の事をメモしておく。
結論を書いておくと、Mojave用のmacOS SDK headerを追加インストールしたら解決した。

環境

Mac OSX Mojave 10.14.1
Ruby 2.5.3

やったこと

rails new hogeapp -d mysql

おきたこと

Installing mysql2 0.5.2 with native extensions

Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

    current directory: /Users/user_name/Programs/web/foobar-repo/vendor/bundle/ruby/2.5.3/gems/mysql2-0.5.2/ext/mysql2
/Users/user_name/.rbenv/versions/2.5.3/bin/ruby -r (以下略)

どうやらmysql2のビルドに失敗している模様。

試したこと

$ xcode-select --install

$ xcode-select --install                                          
xcode-select: error: command line tools are already installed, use "Software Update" to install updates

もう入ってた。

ビルド時のパス追加

$ bundle config --local build.mysql2 "--with-ldflags=-L/usr/local/opt/openssl/lib --with-cppflags=-I/usr/local/opt/openssl/include"

事象変わらず。

Mojave用のmacOS SDK header追加(これで解決)

sudo installer -pkg /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg -target /

上記コマンドでSDK headerを追加インストールした後、$ bundle installしたら解決した。
$ xcode-select --versionでコマンドラインツールのバージョンを見てみたら2354だったのだけど、このバージョンでpythonインストールに苦戦してた方の記事に助けられた。

SierraあたりからOSXのバージョンアップの度に環境問題起きている気がする。

67
38
2

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
67
38