[Ruby] rbenv global 2.3.0 でバージョンが切り替わらない
調査と対応。凡ミスの記録。
[markdown]
## 状況確認
公式をよく読む。
> [rbenv/rbenv: Groom your app’s Ruby environment](https://github.com/rbenv/rbenv)
### path
`echo $path` で `~/.rbenv/shims` が先に存在する。
“`bash
% echo $path
/Users/****/.rbenv/shims /Users/****/local/bin /usr/local/bin /usr/local/sbin /usr/sbin /sbin /usr/bin /bin /Users/****/.composer/vendor/bin /Users/****/local/lib/node_modules/bin
“`
### ~/.rbenv/version
`rbenv global` コマンドの実行結果が `~/.rbenv/version` ファイルに書き込まれている。
“`bash
% more ~/.rbenv/version
2.3.0
“`
### ~/.rbenv/versions
`~/.rbenv/versions` 以下に必要な ruby version がインストールされている。
“`bash
% ls ~/.rbenv/versions
1.9.3-p551/ 2.2.4/ 2.3.0/
“`
### Homebrew
Homebrew で rbenv と ruby-build がインストールされている。
“`prettyprinted
% brew list |grep “rbenv\|ruby-build”
rbenv
rbenv-default-gems
ruby-build
“`
プロファイルに `eval “$(rbenv init -)”` が追加されている。
“`bash
eval “$(rbenv init -)”
“`
## 原因と対応
正常にインストールされているが `~/.rbenv/version` を見ていないことが分かった。
`rbenv versions` で確認。んっ!?
“`prettyprinted
% rbenv versions
system
1.9.3-p551
* 2.2.4 (set by /Users/****/.ruby-version)
2.3.0
“`
ルートディレクトリ直下に `.ruby-version` が何故かある。。。
“`prettyprinted
% more .ruby-version
2.2.4
% rm .ruby-version
remove .ruby-version? y
“`
再確認。
“`prettyprinted
% rbenv global 2.3.0
% rbenv versions
system
1.9.3-p551
2.2.4
* 2.3.0 (set by /Users/****/.rbenv/version)
“`
教訓: コマンドの出力結果は、きちんと確認しよう。
[/markdown]