LoginSignup
39
35

More than 5 years have passed since last update.

オレオレ rbenv 運用 Tips

Last updated at Posted at 2014-07-07

https://github.com/sstephenson/rbenv では、rbenv を

$ echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bash_profile
$ echo 'eval "$(rbenv init -)"' >> ~/.bash_profile

のように設定すると書いているが、私はちょっとひねって以下のように設定している。

# /etc/profile.d/rbenv.sh
if [ -d "$HOME/.rbenv" ]; then
  export PATH="$HOME/.rbenv/bin:$PATH"
  eval "$(rbenv init --no-rehash -)"
fi

ポイントは2点あって、

  1. /etc/profile.d/rbenv.sh に設定を書く
  2. eval "$(rbenv init --no-rehash -)" のように --no-rehash を付ける

理由としては

  1. は /etc/profile.d ならばファイルの分割ができ、~/.bash_profile よりも綺麗に整理できるため。また >> で追記する必要がないので、冪等性を保ちやすくプロビジョニングツールで設定を記述しやすいため。
  2. は rbenv init - はデフォルトでは rbenv rehash もするが、rbenv rehash は時間がかかるので(下手すると 0.5 sec とかかかる)、ログインのたびにイライラすることになってしまうため。rbenv rehash は bin を持つ新しい gem を入れた時にのみやれば良いので、ログインのたびにやるのはやり過ぎ感しかない。
39
35
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
39
35