takecian

Diary

04 Nov 2013

Mac OS Mavericks で bcrypt-ruby がインストールできない場合の対処

Rails を勉強中に、壁にぶつかった。
has_secure_password を使う際に必要な bcrypt-ruby がインストールできない。

ググってみたら、gcc-42 が見つからないって話はよく見つかるんだけど、
それとは違ってこんなエラーが出る。

[bash]
Building native extensions. This could take a while...
ERROR: Error installing bcrypt-ruby:
ERROR: Failed to build gem native extension.

/Users/usrename/.rvm/rubies/ruby-2.0.0-p247/bin/ruby extconf.rb
creating Makefile

make
compiling bcrypt_ext.c
In file included from /Users/usrename/.rvm/rubies/ruby-2.0.0-p247/include/ruby-2.0.0/ruby.h:33,
from bcrypt_ext.c:1:
/Users/usrename/.rvm/rubies/ruby-2.0.0-p247/include/ruby-2.0.0/ruby/ruby.h:51:21: error: string.h: No such file or directory
/Users/usrename/.rvm/rubies/ruby-2.0.0-p247/include/ruby-2.0.0/ruby/ruby.h:61:21: error: stdint.h: No such file or directory
/Users/usrename/.rvm/rubies/ruby-2.0.0-p247/include/ruby-2.0.0/ruby/ruby.h:64:23: error: inttypes.h: No such file or directory
/Users/usrename/.rvm/rubies/ruby-2.0.0-p247/include/ruby-2.0.0/ruby/ruby.h:68:19: error: stdio.h: No such file or directory
In file included from /Users/usrename/.rvm/rubies/ruby-2.0.0-p247/include/ruby-2.0.0/ruby/ruby.h:70,
from /Users/usrename/.rvm/rubies/ruby-2.0.0-p247/include/ruby-2.0.0/ruby.h:33,
from bcrypt_ext.c:1:
/Users/usrename/.rvm/rubies/ruby-2.0.0-p247/include/ruby-2.0.0/ruby/defines.h:29:21: error: stdlib.h: No such file or directory
In file included from /Users/usrename/.rvm/rubies/ruby-2.0.0-p247/include/ruby-2.0.0/ruby/ruby.h:194,
from /Users/usrename/.rvm/rubies/ruby-2.0.0-p247/include/ruby-2.0.0/ruby.h:33,
from bcrypt_ext.c:1:
[/bash]

Command Line Developer Tools が必要だそうで、

[bash]
xcode-select --install
[/bash]

を実行するとインストールできるようになる。

参考:
installing-rails-on-mavericks - Stackoverflow

ちなみに gcc-42 が見つからない場合の対応策はこちら。

[bash]
sudo ln -s /usr/local/bin/gcc-4.2 /usr/bin/gcc-4.2
[/bash]