[mac] MAMPの環境にrubyのMySQLアダプタをインストールする

MAMPの環境でgem install mysqlを実行すると、以下のエラーになる。

$ sudo gem install mysql
Building native extensions.  This could take a while...
ERROR:  Error installing mysql:
	ERROR: Failed to build gem native extension.

/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby extconf.rb install mysql
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lm... yes
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lz... yes
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lsocket... no
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lnsl... no
checking for mysql_query() in -lmysqlclient... no


Gem files will remain installed in /Library/Ruby/Gems/1.8/gems/mysql-2.7 for inspection.
Results logged to /Library/Ruby/Gems/1.8/gems/mysql-2.7/gem_make.out

MAMPのmysqlは、ヘッダファイル、ライブラリがデフォルトの/usr/local/lib、/usr/local/includeにないので、オプションを指定する必要がある。オプションはいろいろあるが、--with-mysql-configを使うと便利。

MySQL/Ruby

--with-mysql-config[=/path/to/mysql_config]
    mysql_config コマンドの結果からコンパイルパラメータを得ます。 


mysql_config コマンドにパスが通るように、.bash_profileなどで、PATHにMAMPのディレクトリを追加しておくか、--with-mysql-config=/Applications/MAMP/Library/bin/mysql_configを指定する。
ここでは、PATHを設定します。

export PATH=/Applications/MAMP/Library/bin:/Applications/MAMP/bin/php5/bin:/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin:$PATH

再度、インストール。

$ sudo gem install mysql -- --with-mysql-config
Building native extensions.  This could take a while...Successfully installed mysql-2.7
1 gem installed

OK。

トラックバック(0)

このブログ記事を参照しているブログ一覧: MAMPの環境にrubyのMySQLアダプタをインストールする

このブログ記事に対するトラックバックURL: http://www.pistolfly.jp/mt/mt-tb-alt.cgi/404

コメントする