Macで複数バージョンのRubyを使用するための環境を構築する方法


* 自分の環境はHomebrewを導入しているので、今回はHomebrewを通してrbenvを入れます。

## rbenv

### インストール

```console
$ brew install rbenv ruby-build
```

* 確認

	```console
	$ rbenv --version
	rbenv 1.0.0
	```
	
	```console
	$ brew info rbenv
	rbenv: stable 1.0.0 (bottled), HEAD
	Ruby version manager
	https://github.com/rbenv/rbenv#readme
	/usr/local/Cellar/rbenv/1.0.0 (36 files, 61.9K) *
	  Poured from bottle on 2016-05-30 at 09:01:46
	From: https://github.com/Homebrew/homebrew-core/blob/master/Formula/rbenv.rb
	==> Dependencies
	Recommended: ruby-build ✔
	==> Options
	--without-ruby-build
		Build without ruby-build support
	--HEAD
		Install HEAD version
	==> Caveats
	Rbenv stores data under ~/.rbenv by default. If you absolutely need to
	store everything under Homebrew's prefix, include this in your profile:
	  export RBENV_ROOT=/usr/local/var/rbenv
	
	To enable shims and autocompletion, run this and follow the instructions:
	  rbenv init
	```
	
	```console
	$ brew info rbenv
	rbenv: stable 1.0.0 (bottled), HEAD
	Ruby version manager
	https://github.com/rbenv/rbenv#readme
	/usr/local/Cellar/rbenv/1.0.0 (36 files, 61.9K) *
	  Poured from bottle on 2016-05-30 at 09:01:46
	From: https://github.com/Homebrew/homebrew-core/blob/master/Formula/rbenv.rb
	==> Dependencies
	Recommended: ruby-build ✔
	==> Options
	--without-ruby-build
		Build without ruby-build support
	--HEAD
		Install HEAD version
	==> Caveats
	Rbenv stores data under ~/.rbenv by default. If you absolutely need to
	store everything under Homebrew's prefix, include this in your profile:
	  export RBENV_ROOT=/usr/local/var/rbenv
	
	To enable shims and autocompletion, run this and follow the instructions:
	  rbenv init
	LowSE01MacBookPro:pyenv LowSE01$
	LowSE01MacBookPro:pyenv LowSE01$
	LowSE01MacBookPro:pyenv LowSE01$ brew info ruby-build
	ruby-build: stable 20160426, HEAD
	Install various Ruby versions and implementations
	https://github.com/rbenv/ruby-build
	/usr/local/Cellar/ruby-build/20160426 (215 files, 124.6K) *
	  Built from source on 2016-06-02 at 12:57:56
	From: https://github.com/Homebrew/homebrew-core/blob/master/Formula/ruby-build.rb
	==> Dependencies
	Recommended: autoconf ✔, pkg-config ✔, openssl ✔
	==> Options
	--without-autoconf
		Build without autoconf support
	--without-openssl
		Build without openssl support
	--without-pkg-config
		Build without pkg-config support
	--HEAD
		Install HEAD version
	```

### パス設定
* パスを通します

	```console
	$ echo 'export RBENV_ROOT=/usr/local/var/rbenv' >> ~/.bash_profile
	$ echo 'eval "$(rbenv init -)"'          >> ~/.bash_profile
	$ source ~/.bash_profile
	```

## ruby
### インストール

* インストール可能バージョンの確認

	```console
	$ rbenv install --list
	```
	
* インストール実行

	```console
	$ rbenv install 2.3.0
	
	Downloading ruby-2.3.0.tar.bz2...
	-> https://cache.ruby-lang.org/pub/ruby/2.3/ruby-2.3.0.tar.bz2
	Installing ruby-2.3.0...
	Installed ruby-2.3.0 to /Users/LowSE01/.rbenv/versions/2.3.0
	```


### デフォルトバージョン指定
* デフォルトで使用するバージョンを指定する

	```console
	rbenv global 2.3.0
	```

* 確認
	
	```console
	$ ruby --version
	ruby 2.3.0p0 (2015-12-25 revision 53290) [x86_64-darwin14]
	```
	* VersionがインストールしたものになっていればOK。

## IntelliJ + Ruby
### プラグイン
* 名前そのまま、「Ruby」ってプラグインがあったのでインストール。