背景
さくらのレンタルサーバーで動くRubyスクリプトをサクッと作りたくて(別のバージョンのRubyをインストールすることもできそうだけど、そこまですることもないような規模なので)、さくらのレンタルサーバーで ruby --version
したら ruby 1.8.7 (2012-10-12 patchlevel 371) [amd64-freebsd9]
と言われてしまったので開発環境のMacにも同じバージョンのRubyをインストールすることに。すんなりは行かなかったのでメモ。
前提
- Homebrew導入済み
- rbenv導入済み
インストール
いつものように下記実行するがエラー。
$ 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 Homebrew's apple-gcc42 package with this
command: brew tap homebrew/dupes ; brew install apple-gcc42
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 (OS X 10.11.3 using ruby-build 20160130-6-g9e57fb0)
brew tap homebrew/dupes ; brew install apple-gcc42
やれって書いてあるけどそれやっても同じで悩んでいましたが、環境変数 CC
で指定したコンパイラを使ってビルドさせることができるようです。私の環境ではapple-gcc42は /usr/local/Cellar/apple-gcc42/4.2.1-5666.3/bin/gcc-4.2
にインストールされていたので、下記のようにしてやります。
$ CC=/usr/local/Cellar/apple-gcc42/4.2.1-5666.3/bin/gcc-4.2 rbenv install 1.8.7-p371
Downloading ruby-1.8.7-p371.tar.bz2...
-> https://cache.ruby-lang.org/pub/ruby/1.8/ruby-1.8.7-p371.tar.bz2
Installing ruby-1.8.7-p371...
Installed ruby-1.8.7-p371 to /Users/youcune/.anyenv/envs/rbenv/versions/1.8.7-p371
Downloading rubygems-1.6.2.tgz...
-> https://dqw8nmjcqpjn7.cloudfront.net/cb5261818b931b5ea2cb54bc1d583c47823543fcf9682f0d6298849091c1cea7
Installing rubygems-1.6.2...
Installed rubygems-1.6.2 to /Users/youcune/.anyenv/envs/rbenv/versions/1.8.7-p371
インストールされていることを確認。
$ rbenv versions
system
1.8.7-p371
* 2.3.0 (set by /Users/youcune/.anyenv/envs/rbenv/version)