Why isn't chruby saving my default Ruby?

6.1k Views Asked by At

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?

4

There are 4 best solutions below

0
On BEST ANSWER

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
0
On

so, the fix I've found so far is to put in a .ruby-version file in my home directory.

currently the .ruby-version file looks like:

2.1.2

... that's it, just the number of the ruby version I wish to use by default.

0
On

To set the chruby default ruby version, you need to use the "u" glob qualifier.

Example: chruby u ruby-3.0.0

#=> * ruby-3.0.0

0
On

Use chruby to list Ruby versions. Then type chruby [version] (in my case, chruby ruby-2.6.5).