LoginSignup
24
25

More than 5 years have passed since last update.

MacにRuby 1.8.7 を今あえてインストールする

Last updated at Posted at 2013-11-21

OS X 10.9 Mavericksから Ruby 2.0.0になり、Ruby 1.8.7のメンテも終了しました。
しかし、どうしても1.8系が必要になったので、インストールしたときのメモ;

1.Command Line Tools(Xcode)、Homebrew、rbenv、ruby-buildのインストール

参考;
→・Ruby 2.0.0 を Homebrew + rbenv で OS X Mountain Lion にインストール

  • Command Line Toolsのダウンロードはこちらから。(要 Apple ID)
#Homebrewは、[ホームページ](http://brew.sh)のインストールコマンドをコピーして、ターミナルで実行
$ ruby -e "$(curl -fsSL https://raw.github.com/mxcl/homebrew/go)"  #最近のコマンドを使用すること
$ brew update  #Homebrew自体とformulaを最新版に
$ brew upgrade #更新のあるパッケージを再ビルド
$ brew doctor  #Homebrewの診断コマンド;エラーが出なければ OK
$ brew install ruby-build
$ brew install rbenv

rbenvを有効にするため、
~/.bash_profile に eval "$(rbenv init -)" の一行を追加する;
$ open ~/.bash_profile #openは、OS X 独自コマンド
で、~/.bash_profile をエディタ(テキストエディットなど)で開いて、上の一行を追加して保存。
~/.bash_profile がまだない場合は;
$ echo 'eval "$(rbenv init -)"' >> ~/.bash_profile
で作成。
(他のエディタで設定しても可)
$ source ~/.bash_profile #または、ターミナルを再起動

2.Ruby 1.8.7-p374 のインストール

Ruby 1.8.7 のインストールに必要な openssl、readline、apple-gcc42 のインストール

$ brew install openssl
$ brew install readline

$ brew tap homebrew/dupes
$ brew install apple-gcc42

$ source ~/.bash_profile #または、ターミナルを再起動
$ rbenv install -l #インストール可能な Ruby のバージョンを確認
$ CC=/usr/local/bin/gcc-4.2 RUBY_CONFIGURE_OPTS="--with-readline-dir=`brew --prefix readline` --with-openssl-dir=`brew --prefix openssl`" rbenv install 1.8.7-p374 #最新のRuby 1.8.7-p374 のインストール
$ rbenv versions #インストールされたRubyのバージョンを確認
* system (set by /Users/ユーザ名/.rbenv/version)
  1.8.7-p374
# *が現在有効なRubyのバージョン 

$ rbenv global 1.8.7-p374 #Ruby 1.8.7 に切り替える
$ rbenv rehash #切り替えた時は、有効にするために必ず実行

$ rbenv versions
  system
* 1.8.7-p374 (set by /Users/ユーザ名/.rbenv/version)

$ ruby -v #ターミナルでも Ruby のバージョンを確認
ruby 1.8.7 (2013-06-27 patchlevel 374) [i686-darwin13.0.0]

 
(→・関連記事
 

24
25
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
24
25