Ruby 2.2.0 がリリースされました。

rbenv でインストール時にこれまで付けていた openssl、readline の指定が必要なくなっていたので、自分用にメモを残しておきます。 

インストールの手順としては、Ruby 2.1 とほとんど同じ流れだったので、その時の記事も参考にして下さい。
→・Ruby 2.1 を Homebrew + rbenv で OS X Yosemite にインストール


○環境
・OS X 10.10.1 (Yosemite)
・Ruby 2.2.0


○手順
 1.Command Line Tools のインストール
その前に、入っているかどうか確認;
$ cc --version
xcode-select: note: no developer tools were found at '/Applications/Xcode.app', requesting install. Choose an option in the dialog to download the command line developer tools.

このように表示されたら、Command Line Tools が入っていないのでインストールする必要があります。

ターミナルから;
$ xcode-select --install
xcode-select: note: install requested for command line developer tools

ここでパネルが出るので、「Install」を選びます。
(「Get Xcode」を選ぶと Xcode がインストールされます。)

インストールが終わったら、もう一度確認;
$ cc --version
Apple LLVM version 6.0 (clang-600.0.56) (based on LLVM 3.5svn)
Target: x86_64-apple-darwin14.0.0
Thread model: posix

無事、Command Line Tools がインストールされました。


あるいは、従来と同じく、
からダウンロードできます。
(Command Line Tools (OS X 10.10) for Xcode - Xcode 6.1.1 以上を選びます。)

もちろん、Xcode 経由でインストールしても構いません。
 

2.Homebrew のインストール
Homebrew のウェブサイトから、最新のインストールコマンドをコピーして、ターミナルで実行します。
 
$ ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

※インストール済みならば;
$ brew update (Homebrew 自体と formula を最新版に)
$ brew upgrade (更新のあるパッケージを再ビルド)

$ brew doctor ("Your system is ready to brew." と表示されれば問題ないです。)


3.readline のインストール
irb や pry で日本語を使う時に、OS X 標準の readline では日本語が表示されないのでインストールします。 
$ brew install readline

※インストール済みならば;
$ brew upgrade readline
 
(openssl は rbenv での rubyインストール時に自動でインストールされるのでしなくてもよいです。)


4.ruby-build、rbenv のインストール
$ brew install ruby-build
$ brew install rbenv

※インストール済みならば;
$ brew upgrade ruby-build
$ brew upgrade rbenv 

~/.bash_profile に設定を追加;
$ echo 'if which rbenv > /dev/null; then eval "$(rbenv init -)"; fi' >> .bash_profile

ターミナルを再起動して、設定を有効に; 
$ source .bash_profile


5.Ruby のインストール
インストール可能な Ruby のバージョンを確認;  
$ rbenv install -l
Available versions:
   ...
   ...
  2.2.0 
   ...

最新のバージョン(2.2.0)をインストール;
$ rbenv install 2.2.0
Downloading openssl-1.0.1j.tar.gz...
...
Installing openssl-1.0.1j...
Installed openssl-1.0.1j to /Users/(ユーザー名)/.rbenv/versions/2.2.0

Downloading ruby-2.2.0.tar.gz...
... 
Installing ruby-2.2.0...
Installed ruby-2.2.0 to /Users/(ユーザー名)/.rbenv/versions/2.2.0


〈インストール時のオプション設定について〉
・openssl について
RUBY_CONFIGURE_OPTS="--with-openssl-dir=`brew --prefix openssl`" の指定は必要なくなっています。

指定を付けなくても、Ruby インストール時に openssl もインストールされます。
ただし、/.rbenv/versions/2.2.0 ディレクトリにインストールされるので、
$ brew list としても、openssl は表示されません。
 
また、あらかじめ、
$ brew install openssl
と openssl をインストールしておけばそれを使います。


・readline について
RUBY_CONFIGURE_OPTS="--with-readline-dir=`brew --prefix readline`" の指定は必要なくなっています。

ただし、あらかじめ、
$ brew install readline
と readline をインストールしておかないと、Ruby インストール時に readline のインストールはされないので注意が必要です。 


6. Ruby のバージョンの設定
インストールされている Ruby とデフォルトのバージョンを確認;
$ rbenv versions
* system (set by /Users/(ユーザー名)/.rbenv/version)
  2.2.0

デフォルトを Ruby 2.2.0 に変更;
$ rbenv global 2.2.0

設定を有効に;
$ rbenv rehash

もう一度、確認;
$ rbenv versions
  system
* 2.2.0 (set by /Users/(ユーザー名)/.rbenv/version)

rbenv で設定されているバージョンを表示;
$ rbenv version
 2.0.0 (set by /Users/(ユーザー名)/.rbenv/version)

実際に起動するバージョンを表示;
$ ruby -v
ruby 2.2.0p0 (2014-12-25 revision 49005) [x86_64-darwin14]


7.Ruby の動作確認
$ irb (irb を起動)
irb(main):001:0> "あいう" (readline で日本語が使えるか確認)
=> "あいう"
irb(main):002:0> Readline::VERSION
=> "6.3"  (Homebrew でインストールされたReadlineが使われている)
irb(main):003:0> require 'openssl' (opensslが使えるか確認)
=> true
irb(main):004:0> OpenSSL::OPENSSL_VERSION
=> "OpenSSL 1.0.1j 15 Oct 2014" (Homebrew でインストールされたopensslが使われている)
irb(main):005:0> require 'zlib'
=> true
irb(main):006:0> require 'psych'
=> true
irb(main):007:0> require 'open-uri'
=> true
irb(main):008:0> open('https://www.google.com/').read (SSL利用時に証明書エラーが出ないか確認)
=> "<!doctype html><html itemscope=\"\" itemtype=\"http://schema.org/WebPage\" lang=\"ja\"><head><meta content=\"\x{90A2}
(中略)
</body></html>" (エラーが出なければ OK)

・上下のカーソルキーを押して、 irb で今使ったコマンドの履歴が出るかも確認。
(readline が使えているか確認)


以上で、無事 Ruby 2.2.0 がインストールされました!


参考;
→・rbenvでMacにRuby 2.2.0 インストール(オプション指定最新版 - Qiita