rbenv で Ruby1.8.7-p358 インストールするも GCC がなんやら言われた時の対応策

2012/10/20

Ruby技術者認定試験を受けようと思い立ち、 Mac OS X 10.8.2 へ Ruby1.8.7 を rbenv 経由でインストールせんとす。 そこで GCC やらなんやらにガタガタ言われての対応を以下に。

# rbenv versions
1.8.7-p358
1.9.3-p0
* 1.9.3-p194 (set by /Users/USERNAME/.rbenv/version)
1.9.3-preview1

rbenv install するも GCC がほげほげとエラー

rbenv install 1.8.7-p358

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

zsh: exit 1 “`

参考1

rbenvのインストール - メモ帳を参考に Downloads · kennethreitz/osx-gcc-installer からpkgをダウンロードしてインストール。

GCCインストール後に rbenv install もエラー

# rbenv install 1.8.7-p358
Downloading http://ftp.ruby-lang.org/pub/ruby/1.8/ruby-1.8.7-p358.tar.gz...
Installing ruby-1.8.7-p358...

BUILD FAILED

Inspect or clean up the working tree at /var/folders/rz/l0r480g501z5g0l2bj4h7hfh0000gn/T/ruby-build.20121020155254.1500
Results logged to /var/folders/rz/l0r480g501z5g0l2bj4h7hfh0000gn/T/ruby-build.20121020155254.1500.log

Last 10 log lines:
cc -dynamic -bundle -undefined suppress -flat_namespace -o ../../../.ext/i686-darwin12.2.0/racc/cparse.bundle cparse.o -L. -L../../.. -L. -L'/Users/jipp/.rbenv/versions/1.8.7-p358/lib' -ldl -lobjc
ld: warning: directory not found for option '-L/Users/jipp/.rbenv/versions/1.8.7-p358/lib'
compiling readline
/usr/bin/gcc-4.2 -I. -I../.. -I../../. -I../.././ext/readline -DHAVE_READLINE_READLINE_H -DHAVE_READLINE_HISTORY_H -DHAVE_RL_FILENAME_COMPLETION_FUNCTION -DHAVE_RL_COMPLETION_MATCHES -DHAVE_RL_DEPREP_TERM_FUNCTION -DHAVE_RL_COMPLETION_APPEND_CHARACTER -DHAVE_RL_BASIC_WORD_BREAK_CHARACTERS -DHAVE_RL_COMPLETER_WORD_BREAK_CHARACTERS -DHAVE_RL_BASIC_QUOTE_CHARACTERS -DHAVE_RL_COMPLETER_QUOTE_CHARACTERS -DHAVE_RL_FILENAME_QUOTE_CHARACTERS -DHAVE_RL_ATTEMPTED_COMPLETION_OVER -DHAVE_RL_LIBRARY_VERSION -DHAVE_RL_EVENT_HOOK -DHAVE_RL_CLEANUP_AFTER_SIGNAL -DHAVE_REPLACE_HISTORY_ENTRY -DHAVE_REMOVE_HISTORY -I'/Users/jipp/.rbenv/versions/1.8.7-p358/include' -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -I'/Users/jipp/.rbenv/versions/1.8.7-p358/include' -fno-common -g -O2 -pipe -fno-common -c readline.c
readline.c: In function username_completion_proc_call:
readline.c:730: error: username_completion_function undeclared (first use in this function)
readline.c:730: error: (Each undeclared identifier is reported only once
readline.c:730: error: for each function it appears in.)
make[1]: *** [readline.o] Error 1
make: *** [all] Error 1
zsh: exit 1

参考2

osxにてrbenvを使ってインストールしたrubyのアーキテクチャーがまちまちに、、、 - 駄日記がヒット。 参考にして調査。

readline のバージョン

# ls /usr/local/Cellar/readline/6.2.2
CHANGES ChangeLog README lib
COPYING INSTALL_RECEIPT.json include share

arch は x86_64

# uname -a
Darwin jipp 12.2.0 Darwin Kernel Version 12.2.0: Sat Aug 25 00:48:52 PDT 2012; root:xnu-2050.18.24~1/RELEASE_X86_64 x86_64

以下をexport した

# export CONFIGURE_OPTS="--with-arch=x86_64 --with-readline-dir=/usr/local/Cellar/readline/6.2.2" CFLAGS="-arch x86_64" LDFLAGS="-arch x86_64"

再々実行 rbenv install

# rbenv install 1.8.7-p358 Downloading http://ftp.ruby-lang.org/pub/ruby/1.8/ruby-1.8.7-p358.tar.gz...
Installing ruby-1.8.7-p358...
Installed ruby-1.8.7-p358 to /Users/jipp/.rbenv/versions/1.8.7-p358
Downloading http://production.cf.rubygems.org/rubygems/rubygems-1.6.2.tgz...
Installing rubygems-1.6.2...
Installed rubygems-1.6.2 to /Users/jipp/.rbenv/versions/1.8.7-p358

うまくいったようだ

確認

# rbenv global 1.8.7-p358

# rbenv rehash

# rbenv version
1.8.7-p358 (set by /Users/jipp/.rbenv/version)

# ruby -v
ruby 1.8.7 (2012-02-08 patchlevel 358) [i686-darwin12.2.0]

まいっか