scramble cadenza

技術ネタのガラクタ置き場

Mountain Lion で ruby-1.8.7を動かす

前準備

公式サイトの通りにやって問題なかった

  • rbenv をインストールする
  • ruby-build をインストールする
  • homebrew をインストールする

やってみたこと

実は ruby-build では、rubyのversionの古いものが install できなかった。(1.9.3はrbenv-buildでインストール可能だった)
この記事は rbenv-build を用いて rubyの1.8.7 を入れてみた時のログ。OS はタイトルにもある通り Mountain Lion

結果から言うと

を新たにインストールする必要があった。

apple-gcc42

試しに 1.8.7-p371 をインストールしてみると以下のように怒られる。

% rbenv install 1.8.7-p371
 

ERROR: This package must be compiled with GCC, but ruby-build couldn't

find a suitable `gcc` executable on your system. Please install GCC

and try again.

 

DETAILS: Apple no longer includes the official GCC compiler with Xcode

as of version 4.2. Instead, the `gcc` executable is a symlink to

`llvm-gcc`, a modified version of GCC which outputs LLVM bytecode.

 

For most programs the `llvm-gcc` compiler works fine. However,

versions of Ruby older than 1.9.3-p125 are incompatible with

`llvm-gcc`. To build older versions of Ruby you must have the official

GCC compiler installed on your system.

 

TO FIX THE PROBLEM: Install the official GCC compiler using these

packages: https://github.com/kennethreitz/osx-gcc-installer/downloads

 

You will need to install the official GCC compiler to build older

versions of Ruby even if you have installed Apple's Command Line Tools

for Xcode package. The Command Line Tools for Xcode package only

includes `llvm-gcc`.

 

BUILD FAILED

どういう事かというと

  • 現在のgccはllvm-gcc-4.2というものである*1
  • インストールするためにはofficialなGCCが必要。
  • Xcodeにはllvm-gccしか入っていないよ。

ということらしい。
official なGCCをインストールすればよくて、homebrewでinstallすることにする。
色々調べていくと、officialなGCC の代わりに apple-gcc42 を使えば良いことがわかった。

brew install https://raw.github.com/Homebrew/homebrew-dupes/master/apple-gcc42.rb

これでapple-gcc42のインストールは完了。

XQuartz

それ以外にも必要なパッケージ( openssl と readline )をhomebrewでインストールする。
デフォルトで入っている openssl にはいい噂を聞かないので、新たに openssl をhomebrewで入れることにする。 そして homebrew の openssl を使うように指定する。

brew link openssl --force
brew link readline --force


これで準備出来たのでいざインストールする

% CONFIGURE_OPTS="--with-openssl-dir=/usr/local --with-readline-dir=/usr/local" rbenv install 1.8.7-p371

Downloading ruby-1.8.7-p371.tar.gz...

-> http://ftp.ruby-lang.org/pub/ruby/1.8/ruby-1.8.7-p371.tar.gz

Installing ruby-1.8.7-p371...

 

BUILD FAILED

 

Inspect or clean up the working tree at /var/folders/4j/3d_grz7d58d44dpyvd5yd47m0000gn/T/ruby-build.20130329102722.83174

Results logged to /var/folders/4j/3d_grz7d58d44dpyvd5yd47m0000gn/T/ruby-build.20130329102722.83174.log

 

Last 10 log lines:

tcltklib.c:9862: error: expected ‘;’ before ‘event’

tcltklib.c:9892: error: ‘struct dummy_TkMenu’ has no member named ‘menuType’

tcltklib.c:9897: error: ‘struct dummy_TkMenu’ has no member named ‘menuType’

tcltklib.c:9915: error: ‘event’ undeclared (first use in this function)

tcltklib.c:9916: error: ‘ConfigureNotify’ undeclared (first use in this function)

tcltklib.c:9917: error: ‘Tk_FakeWin’ has no member named ‘display’

tcltklib.c:9919: error: ‘Tk_FakeWin’ has no member named ‘window’

tcltklib.c:9920: error: ‘Tk_FakeWin’ has no member named ‘display’

make[1]: *** [tcltklib.o] Error 1

make: *** [all] Error 1

make[1]: *** [tcltklib.o] Error 1 でぐぐったら
https://github.com/sstephenson/ruby-build/issues/193
が出てきた。

どうやらXQuartzをインストールする必要があるらしい。
手順は以下のとおり

これで再度チャレンジ

% CONFIGURE_OPTS="--with-openssl-dir=/usr/local --with-readline-dir=/usr/local" rbenv install 1.8.7-p371

Downloading ruby-1.8.7-p371.tar.gz...
-> http://ftp.ruby-lang.org/pub/ruby/1.8/ruby-1.8.7-p371.tar.gz
Installing ruby-1.8.7-p371...
Installed ruby-1.8.7-p371 to /Users/horowitz/.rbenv/versions/1.8.7-p371

Downloading rubygems-1.6.2.tar.gz...
-> http://dqw8nmjcqpjn7.cloudfront.net/0c95a9869914ba1a45bf71d3b8048420
Installing rubygems-1.6.2...
Installed rubygems-1.6.2 to /Users/horowitz/.rbenv/versions/1.8.7-p371

できた!

参考にさせていただいたサイト

OS X で rbenv を使って ruby 1.9.3 or 2.0.0 の環境を作る #Ruby #AdventCalendar #開発環境 - Qiita
http://qiita.com/items/9dd797f42e7bea674705

Ruby1.8系をrbenvで追加インストールしたら少し嵌る - Fevnirのブログ(仮)
http://fevnir-r.hateblo.jp/entry/2013/03/11/215422

[Mac] Homebrew で apple-gcc42 をインストールする方法 | CodeNote.net
http://codenote.net/mac/homebrew/751.html

*1:/usr/bin/gcc lrwxr-xr-x 1 root wheel 12 3 9 02:06 /usr/bin/gcc@ -> llvm-gcc-4.2 1