the glue


Mac で Rails を使う

Mac ( OS X ) に Rails をインストールしようとするといつもコケるのでメモ


  • OS X Yosemite
  • Homebrew が導入済みであること
  • Homebrew で Ruby をインストール済みであること
$ brew -v
Homebrew 0.9.5

$ ruby -v
ruby 2.2.2p95 (2015-04-13 revision 50295) [x86_64-darwin14]


Building native extensions.  This could take a while...
ERROR:  Error installing rails:
    ERROR: Failed to build gem native extension.

    /usr/local/opt/ruby/bin/ruby -r ./siteconf20150421-1193-63p9ed.rb extconf.rb
checking if the C compiler accepts ... yes
checking if the C compiler accepts -Wno-error=unused-command-line-argument-hard-error-in-future... no
Building nokogiri using packaged libraries.
The file "/usr/include/iconv.h" is missing in your build environment,
which means you haven't installed Xcode Command Line Tools properly.

To install Command Line Tools, try running `xcode-select --install` on
terminal and follow the instructions.  If it fails, open,
select from the menu "Xcode" - "Open Developer Tool" - "More Developer
Tools" to open the developer site, download the installer for your OS
version and run it.
*** 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:

extconf failed, exit code 1

Gem files will remain installed in /usr/local/lib/ruby/gems/2.2.0/gems/nokogiri- for inspection.
Results logged to /usr/local/lib/ruby/gems/2.2.0/extensions/x86_64-darwin-14/2.2.0/nokogiri-

要は nokogiri が入らないわけです。
(あと xcode-select --install もやれって言われているような... )



# とりあえず言われたことをやりましょう
$ xcode-select --install

$ brew tap homebrew/dupes
$ brew install libxml2 libxslt
$ brew install libiconv

nokogiri だけ先にインストール


# まずは nokogiri をなんとかインストール
$ gem install nokogiri -- --use-system-libraries --with-xml2-include=/usr/include/libxml2 --with-xml2- lib=/usr/lib/

# rails をインストール
$ gem install rails


$ rails -v
Rails 4.2.1