RBENV_DEBUG を環境変数に設定すると rbenv の実行ログが見れる


今回、rbenv の挙動を追ってて、見つけたのでメモします。

値は何でもいいので、RBENV_DEBUG を設定して実行

```
RBENV_DEBUG=1 ruby -v
```


## 実行結果

```

[vagrant@localhost ~]$ RBENV_DEBUG=1 ruby -v
+ program=ruby
+ '[' ruby = ruby ']'
+ for arg in '"$@"'
+ case "$arg" in
+ export RBENV_ROOT=/home/vagrant/.rbenv
+ RBENV_ROOT=/home/vagrant/.rbenv
+ exec /home/vagrant/.rbenv/libexec/rbenv exec ruby -v
+ [rbenv:15] enable -f /home/vagrant/.rbenv/libexec/../libexec/rbenv-realpath.dylib realpath
+ [rbenv:21] '[' -n '' ']'
++ [rbenv:25] head -1
++ [rbenv:25] type -p greadlink readlink
+ [rbenv:25] READLINK=/bin/readlink
+ [rbenv:26] '[' -z /bin/readlink ']'
+ [rbenv:50] '[' -z /home/vagrant/.rbenv ']'
+ [rbenv:53] RBENV_ROOT=/home/vagrant/.rbenv
+ [rbenv:55] export RBENV_ROOT
+ [rbenv:57] '[' -z '' ']'
++ [rbenv:58] pwd
+ [rbenv:58] RBENV_DIR=/home/vagrant
+ [rbenv:67] export RBENV_DIR
+ [rbenv:70] shopt -s nullglob
++ [rbenv:72] abs_dirname /home/vagrant/.rbenv/libexec/rbenv
+++ [rbenv:36] pwd
++ [rbenv:36] local cwd=/home/vagrant
++ [rbenv:37] local path=/home/vagrant/.rbenv/libexec/rbenv
++ [rbenv:39] '[' -n /home/vagrant/.rbenv/libexec/rbenv ']'
++ [rbenv:40] cd /home/vagrant/.rbenv/libexec
++ [rbenv:41] local name=rbenv
+++ [rbenv:42] resolve_link rbenv
+++ [rbenv:32] /bin/readlink rbenv
+++ [rbenv:42] true
++ [rbenv:42] path=
++ [rbenv:39] '[' -n '' ']'
++ [rbenv:45] pwd
++ [rbenv:46] cd /home/vagrant
+ [rbenv:72] bin_path=/home/vagrant/.rbenv/libexec
+ [rbenv:73] for plugin_bin in '"${RBENV_ROOT}/plugins/"*/bin'
+ [rbenv:74] PATH=/home/vagrant/.rbenv/plugins/ruby-build/bin:/home/vagrant/.rbenv/shims:/home/vagrant/.rbenv/bin:/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/home/vagrant/bin
+ [rbenv:76] export PATH=/home/vagrant/.rbenv/libexec:/home/vagrant/.rbenv/plugins/ruby-build/bin:/home/vagrant/.rbenv/shims:/home/vagrant/.rbenv/bin:/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/home/vagrant/bin
+ [rbenv:76] PATH=/home/vagrant/.rbenv/libexec:/home/vagrant/.rbenv/plugins/ruby-build/bin:/home/vagrant/.rbenv/shims:/home/vagrant/.rbenv/bin:/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/home/vagrant/bin
+ [rbenv:78] RBENV_HOOK_PATH=:/home/vagrant/.rbenv/rbenv.d
+ [rbenv:79] '[' /home/vagrant/.rbenv '!=' /home/vagrant/.rbenv ']'
+ [rbenv:83] RBENV_HOOK_PATH=:/home/vagrant/.rbenv/rbenv.d:/usr/local/etc/rbenv.d:/etc/rbenv.d:/usr/lib/rbenv/hooks
+ [rbenv:87] export RBENV_HOOK_PATH
+ [rbenv:89] shopt -u nullglob
+ [rbenv:92] command=exec
+ [rbenv:93] case "$command" in
++ [rbenv:101] command -v rbenv-exec
+ [rbenv:101] command_path=/home/vagrant/.rbenv/libexec/rbenv-exec
+ [rbenv:102] '[' -z /home/vagrant/.rbenv/libexec/rbenv-exec ']'
+ [rbenv:107] shift 1
+ [rbenv:108] exec /home/vagrant/.rbenv/libexec/rbenv-exec ruby -v
+ [rbenv-exec:20] '[' ruby = --complete ']'
++ [rbenv-exec:24] rbenv-version-name
+ [rbenv-version-name:6] '[' -z '' ']'
++ [rbenv-version-name:7] rbenv-version-file
+ [rbenv-version-file:20] find_local_version_file /home/vagrant
+ [rbenv-version-file:7] local root=/home/vagrant
+ [rbenv-version-file:8] '[' -n /home/vagrant ']'
+ [rbenv-version-file:9] '[' -e /home/vagrant/.ruby-version ']'
+ [rbenv-version-file:12] '[' -e /home/vagrant/.rbenv-version ']'
+ [rbenv-version-file:16] root=/home
+ [rbenv-version-file:8] '[' -n /home ']'
+ [rbenv-version-file:9] '[' -e /home/.ruby-version ']'
+ [rbenv-version-file:12] '[' -e /home/.rbenv-version ']'
+ [rbenv-version-file:16] root=
+ [rbenv-version-file:8] '[' -n '' ']'
+ [rbenv-version-file:21] '[' /home/vagrant = /home/vagrant ']'
+ [rbenv-version-file:23] global_version_file=/home/vagrant/.rbenv/version
+ [rbenv-version-file:25] '[' -e /home/vagrant/.rbenv/version ']'
+ [rbenv-version-file:26] echo /home/vagrant/.rbenv/version
+ [rbenv-version-name:7] RBENV_VERSION_FILE=/home/vagrant/.rbenv/version
++ [rbenv-version-name:8] rbenv-version-file-read /home/vagrant/.rbenv/version
+ [rbenv-version-file-read:6] VERSION_FILE=/home/vagrant/.rbenv/version
+ [rbenv-version-file-read:8] '[' -e /home/vagrant/.rbenv/version ']'
+ [rbenv-version-file-read:11] IFS='
'
+ [rbenv-version-file-read:12] words=($(cut -b 1-1024 "$VERSION_FILE"))
++ [rbenv-version-file-read:12] cut -b 1-1024 /home/vagrant/.rbenv/version
+ [rbenv-version-file-read:13] version=2.1.4
+ [rbenv-version-file-read:15] '[' -n 2.1.4 ']'
+ [rbenv-version-file-read:16] echo 2.1.4
+ [rbenv-version-file-read:17] exit
+ [rbenv-version-name:8] RBENV_VERSION=2.1.4
+ [rbenv-version-name:11] '[' -z 2.1.4 ']'
+ [rbenv-version-name:11] '[' 2.1.4 = system ']'
+ [rbenv-version-name:21] version_exists 2.1.4
+ [rbenv-version-name:17] local version=2.1.4
+ [rbenv-version-name:18] '[' -d /home/vagrant/.rbenv/versions/2.1.4 ']'
+ [rbenv-version-name:22] echo 2.1.4
+ [rbenv-exec:24] RBENV_VERSION=2.1.4
+ [rbenv-exec:25] RBENV_COMMAND=ruby
+ [rbenv-exec:27] '[' -z ruby ']'
+ [rbenv-exec:32] export RBENV_VERSION
++ [rbenv-exec:33] rbenv-which ruby
+ [rbenv-which:14] '[' ruby = --complete ']'
+ [rbenv-which:29] RBENV_COMMAND=ruby
+ [rbenv-which:31] '[' -z ruby ']'
+ [rbenv-which:36] RBENV_VERSION=2.1.4
+ [rbenv-which:38] '[' 2.1.4 = system ']'
+ [rbenv-which:42] RBENV_COMMAND_PATH=/home/vagrant/.rbenv/versions/2.1.4/bin/ruby
+ [rbenv-which:45] OLDIFS='
'
+ [rbenv-which:46] IFS='
'
+ [rbenv-which:46] scripts=(`rbenv-hooks which`)
++ [rbenv-which:46] rbenv-hooks which
+ [rbenv-hooks:9] '[' which = --complete ']'
+ [rbenv-hooks:16] RBENV_COMMAND=which
+ [rbenv-hooks:17] '[' -z which ']'
+ [rbenv-hooks:22] enable -f /home/vagrant/.rbenv/libexec/rbenv-realpath.dylib realpath
+ [rbenv-hooks:23] '[' -n '' ']'
++ [rbenv-hooks:27] head -1
++ [rbenv-hooks:27] type -p greadlink readlink
+ [rbenv-hooks:27] READLINK=/bin/readlink
+ [rbenv-hooks:28] '[' -z /bin/readlink ']'
+ [rbenv-hooks:52] IFS=:
+ [rbenv-hooks:52] hook_paths=($RBENV_HOOK_PATH)
+ [rbenv-hooks:54] shopt -s nullglob
+ [rbenv-hooks:55] for path in '"${hook_paths[@]}"'
+ [rbenv-hooks:55] for path in '"${hook_paths[@]}"'
+ [rbenv-hooks:55] for path in '"${hook_paths[@]}"'
+ [rbenv-hooks:55] for path in '"${hook_paths[@]}"'
+ [rbenv-hooks:55] for path in '"${hook_paths[@]}"'
+ [rbenv-hooks:60] shopt -u nullglob
+ [rbenv-which:47] IFS='
'
+ [rbenv-which:52] '[' -x /home/vagrant/.rbenv/versions/2.1.4/bin/ruby ']'
+ [rbenv-which:53] echo /home/vagrant/.rbenv/versions/2.1.4/bin/ruby
+ [rbenv-exec:33] RBENV_COMMAND_PATH=/home/vagrant/.rbenv/versions/2.1.4/bin/ruby
+ [rbenv-exec:34] RBENV_BIN_PATH=/home/vagrant/.rbenv/versions/2.1.4/bin
+ [rbenv-exec:36] OLDIFS='
'
+ [rbenv-exec:37] IFS='
'
+ [rbenv-exec:37] scripts=(`rbenv-hooks exec`)
++ [rbenv-exec:37] rbenv-hooks exec
+ [rbenv-hooks:9] '[' exec = --complete ']'
+ [rbenv-hooks:16] RBENV_COMMAND=exec
+ [rbenv-hooks:17] '[' -z exec ']'
+ [rbenv-hooks:22] enable -f /home/vagrant/.rbenv/libexec/rbenv-realpath.dylib realpath
+ [rbenv-hooks:23] '[' -n '' ']'
++ [rbenv-hooks:27] head -1
++ [rbenv-hooks:27] type -p greadlink readlink
+ [rbenv-hooks:27] READLINK=/bin/readlink
+ [rbenv-hooks:28] '[' -z /bin/readlink ']'
+ [rbenv-hooks:52] IFS=:
+ [rbenv-hooks:52] hook_paths=($RBENV_HOOK_PATH)
+ [rbenv-hooks:54] shopt -s nullglob
+ [rbenv-hooks:55] for path in '"${hook_paths[@]}"'
+ [rbenv-hooks:55] for path in '"${hook_paths[@]}"'
+ [rbenv-hooks:56] for script in '"$path/$RBENV_COMMAND"/*.bash'
+ [rbenv-hooks:57] realpath /home/vagrant/.rbenv/rbenv.d/exec/gem-rehash.bash
++ [rbenv-hooks:38] pwd
+ [rbenv-hooks:38] local cwd=/home/vagrant
+ [rbenv-hooks:39] local path=/home/vagrant/.rbenv/rbenv.d/exec/gem-rehash.bash
+ [rbenv-hooks:41] '[' -n /home/vagrant/.rbenv/rbenv.d/exec/gem-rehash.bash ']'
+ [rbenv-hooks:42] cd /home/vagrant/.rbenv/rbenv.d/exec
+ [rbenv-hooks:43] local name=gem-rehash.bash
++ [rbenv-hooks:44] resolve_link gem-rehash.bash
++ [rbenv-hooks:34] /bin/readlink gem-rehash.bash
++ [rbenv-hooks:44] true
+ [rbenv-hooks:44] path=
+ [rbenv-hooks:41] '[' -n '' ']'
++ [rbenv-hooks:47] pwd
+ [rbenv-hooks:47] echo /home/vagrant/.rbenv/rbenv.d/exec/gem-rehash.bash
+ [rbenv-hooks:48] cd /home/vagrant
+ [rbenv-hooks:55] for path in '"${hook_paths[@]}"'
+ [rbenv-hooks:55] for path in '"${hook_paths[@]}"'
+ [rbenv-hooks:55] for path in '"${hook_paths[@]}"'
+ [rbenv-hooks:60] shopt -u nullglob
+ [rbenv-exec:38] IFS='
'
+ [rbenv-exec:39] for script in '"${scripts[@]}"'
+ [rbenv-exec:40] source /home/vagrant/.rbenv/rbenv.d/exec/gem-rehash.bash
++ [gem-rehash.bash:1] export RUBYLIB=/home/vagrant/.rbenv/rbenv.d/exec/gem-rehash:
++ [gem-rehash.bash:1] RUBYLIB=/home/vagrant/.rbenv/rbenv.d/exec/gem-rehash:
+ [rbenv-exec:43] shift 1
+ [rbenv-exec:44] '[' 2.1.4 '!=' system ']'
+ [rbenv-exec:45] export PATH=/home/vagrant/.rbenv/versions/2.1.4/bin:/home/vagrant/.rbenv/libexec:/home/vagrant/.rbenv/plugins/ruby-build/bin:/home/vagrant/.rbenv/shims:/home/vagrant/.rbenv/bin:/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/home/vagrant/bin
+ [rbenv-exec:45] PATH=/home/vagrant/.rbenv/versions/2.1.4/bin:/home/vagrant/.rbenv/libexec:/home/vagrant/.rbenv/plugins/ruby-build/bin:/home/vagrant/.rbenv/shims:/home/vagrant/.rbenv/bin:/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/home/vagrant/bin
+ [rbenv-exec:47] exec -a ruby /home/vagrant/.rbenv/versions/2.1.4/bin/ruby -v
ruby 2.1.4p265 (2014-10-27 revision 48166) [x86_64-linux]
```

## 各バージョン
centos 6.6
rbenv 0.4.0-129-g7e0e85b

## 参考リンク
* [rbenv rehashは何をやっているのか？](http://dqn.sakusakutto.jp/2014/02/rbenv_rehash_what_it_does.html)