rubyruby-installchruby

Why isn't chruby saving my default Ruby?


I'm setting up a new machine and trying to install Ruby with chruby. I used ruby-install to install both ruby 2.3 and 2.1.2 because that's what everybody else on my team is running.

When I run chruby I get:

ruby-2.1.2 ruby-2.3.0

Then I run:

chruby ruby-2.1.2

and:

$ chruby
* ruby-2.1.2
  ruby-2.3.0

$ ruby -v
ruby 2.1.2p95 (2014-05-08 revision 45877) [x86_64-darwin14.0]

The problem is that when I close terminal and open it again the default Ruby version goes back to ruby-2.3.0. How can I set a default version with chruby?


Solution

  • Invoke Chruby at Shell Initialization

    Unlike RVM or other Ruby managers, chruby doesn't really have a concept of a "default" Ruby. You need to actually define one during each shell initialization. To do this, you need to:

    1. Source the chruby.sh script.
    2. Select the default Ruby to be exported to your environment.

    As an example, you can add the following to your shell's ~/.bashrc or other interactive-shell startup file:

    . /usr/local/share/chruby/chruby.sh
    chruby ruby-2.3.0