Gambai
Gambai

Reputation: 690

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?

Upvotes: 6

Views: 7061

Answers (4)

JosiahF
JosiahF

Reputation: 11

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

Upvotes: 1

Qasim
Qasim

Reputation: 1580

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

Upvotes: 0

Todd A. Jacobs
Todd A. Jacobs

Reputation: 84343

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

Upvotes: 6

Gambai
Gambai

Reputation: 690

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.

Upvotes: 4

Related Questions