mac os x 10.8.2 に ruby on rails を install したときのメモ

mac os x 10.8.2 に ruby on rails を install して、いくつかはまったので、メモ

はまったこと

  • ruby 1.9.3 だと Rails 3.2.9 の install (gem install rails) が失敗する
  • ruby 1.9.2 を rvm で install するときに、gcc が入ってないと、失敗する

やったこと

基本は下の記事を参考に install しました
ありがとうございます!!!

Mac に RVM で Ruby 1.9.2 と Rails 3.2.1 をインストールした
http://d.hatena.ne.jp/inouetakuya/20120205/1328443579

最初、rails のページに 1.9.3 を使えとあったので、それで進めてましたが
http://rubyonrails.org/download

下のエラーになりました。

$ gem install rails
ERROR: Error installing rails:
invalid gem format for /Users/mitsuaki/.rvm/gems/ruby-1.9.3-p327/cache/railties-3.2.9.gem

ぐぐったら、下の stack overflow に辿りつき

http://stackoverflow.com/questions/11802918/error-failed-to-build-gem-native-extension-when-installing-rails-on-mac-mountia

よーく読むと、下のようなコメントがありました。

This is exactly right, but homebrew isn't needed. All that is needed is to create a symlink from gcc-4.2 to gcc: sudo ln -s /usr/bin/gcc /usr/bin/gcc-4.2 – Justin M. Keyes Dec 9 at 17:48

しかしやっても、状況が変わりません

そこで、ruby 1.9.2 で試そうと思い立ち、

rvm install 1.9.2 をすると、下のエラーになりました

device-3fe8b0:~ mitsuaki$ rvm install 1.9.2
No binary rubies available for: downloads/ruby-1.9.2-p320.
Continuing with compilation. Please read 'rvm mount' to get more information on binary rubies.
Fetching yaml-0.1.4.tar.gz to /Users/mitsuaki/.rvm/archives
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 460k 100 460k 0 0 276k 0 0:00:01 0:00:01 --:--:-- 315k
Extracting yaml to /Users/mitsuaki/.rvm/src/yaml-0.1.4
Configuring yaml in /Users/mitsuaki/.rvm/src/yaml-0.1.4.
Compiling yaml in /Users/mitsuaki/.rvm/src/yaml-0.1.4.
Installing yaml to /Users/mitsuaki/.rvm/usr
Building 'ruby-1.9.2-p320' using clang - but it's not (fully) supported, expect errors.
Installing Ruby from source to: /Users/mitsuaki/.rvm/rubies/ruby-1.9.2-p320, this may take a while depending on your cpu(s)...
ruby-1.9.2-p320 - #downloading ruby-1.9.2-p320, this may take a while depending on your connection...
ruby-1.9.2-p320 - #extracting ruby-1.9.2-p320 to /Users/mitsuaki/.rvm/src/ruby-1.9.2-p320
ruby-1.9.2-p320 - #extracted to /Users/mitsuaki/.rvm/src/ruby-1.9.2-p320
ruby-1.9.2-p320 - #configuring
ruby-1.9.2-p320 - #compiling
ruby-1.9.2-p320 - #installing
Retrieving rubygems-1.8.24
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 371k 100 371k 0 0 631k 0 --:--:-- --:--:-- --:--:-- 951k
Extracting rubygems-1.8.24 ...
Removing old Rubygems files...
Installing rubygems-1.8.24 for ruby-1.9.2-p320 ...
Installation of rubygems completed successfully.
Saving wrappers to '/Users/mitsuaki/.rvm/bin'.
ruby-1.9.2-p320 - #adjusting #shebangs for (gem irb erb ri rdoc testrb rake).
ruby-1.9.2-p320 - #importing default gemsets (/Users/mitsuaki/.rvm/gemsets/), this may take time ...
Install of ruby-1.9.2-p320 - #complete
Ruby 'ruby-1.9.2-p320' was built using clang - but it's not (fully) supported, expect errors.
device-3fe8b0:~ mitsuaki$

こりゃ gcc 入れないとだめそうってことで
まずは 下を参考に brew を入れました

http://mxcl.github.com/homebrew/

もういちど先ほどの stack overflow の記事に従い

http://stackoverflow.com/questions/11802918/error-failed-to-build-gem-native-extension-when-installing-rails-on-mac-mountia

下をやりました

brew --version

should report 0.9.3 or greater

if you have not brew than follow these instrunctions to install it
if you have a older version then update it:
brew update

now you can install gcc-4.2 and create a symbolink link where is aspected by the build system

brew tap homebrew/dupes

brew install apple-gcc42

sudo ln -s /usr/local/bin/gcc-4.2 /usr/bin/gcc-4.2

そうすると無事 1.9.2 が入りました。

Kuwahara-no-MacBook-Air:bin mitsuaki$ rvm install 1.9.2
No binary rubies available for: downloads/ruby-1.9.2-p320.
Continuing with compilation. Please read 'rvm mount' to get more information on binary rubies.
Installing Ruby from source to: /Users/mitsuaki/.rvm/rubies/ruby-1.9.2-p320, this may take a while depending on your cpu(s)...
ruby-1.9.2-p320 - #downloading ruby-1.9.2-p320, this may take a while depending on your connection...
ruby-1.9.2-p320 - #extracting ruby-1.9.2-p320 to /Users/mitsuaki/.rvm/src/ruby-1.9.2-p320
ruby-1.9.2-p320 - #extracted to /Users/mitsuaki/.rvm/src/ruby-1.9.2-p320
ruby-1.9.2-p320 - #configuring
ruby-1.9.2-p320 - #compiling
ruby-1.9.2-p320 - #installing
Removing old Rubygems files...
Installing rubygems-1.8.24 for ruby-1.9.2-p320 ...
Installation of rubygems completed successfully.
Saving wrappers to '/Users/mitsuaki/.rvm/bin'.
ruby-1.9.2-p320 - #adjusting #shebangs for (gem irb erb ri rdoc testrb rake).
ruby-1.9.2-p320 - #importing default gemsets (/Users/mitsuaki/.rvm/gemsets/), this may take time ...
Install of ruby-1.9.2-p320 - #complete
uwahara-no-MacBook-Air:bin mitsuaki$ rvm use 1.9.2
Using /Users/mitsuaki/.rvm/gems/ruby-1.9.2-p320


なんとか rails が入りました

Kuwahara-no-MacBook-Air:bin mitsuaki$ gem update
Updating installed gems
Nothing to update
Kuwahara-no-MacBook-Air:bin mitsuaki$ gem install rails
Fetching: i18n-0.6.1.gem (100%)
Fetching: multi_json-1.5.0.gem (100%)

        • しょーりゃく ----

nstalling RDoc documentation for rdoc-3.12...
Installing RDoc documentation for railties-3.2.9...
Installing RDoc documentation for rails-3.2.9...
Kuwahara-no-MacBook-Air:bin mitsuaki$ rvm use --default 1.9.2
Using /Users/mitsuaki/.rvm/gems/ruby-1.9.2-p320
Kuwahara-no-MacBook-Air:bin mitsuaki$ rails --version
Rails 3.2.9