Why isn't chruby saving my default Ruby?
Asked Answered
E

4

6

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?

Epanorthosis answered 23/2, 2016 at 22:7 Comment(10)
Sounds like the chruby stub isn't getting activated properly when you create a shell. Are you sure it installed successfully?Fluoro
how would I check? when I run chruby, it find the command and runs it... sorry, I'm still new to mac. I installed it with homebrewEpanorthosis
I'm more familiar with rvm and rbenv, but they all work on the same principle. The installation instructions includes a step where you have to add a line to ~/.bashrc. Did you do that? It's easy to miss.Fluoro
I tried it in .bashrc, then I moved it to ~/.bash_profile it's: source /usr/local/opt/chruby/share/chruby/chruby.sh source /usr/local/opt/chruby/share/chruby/auto.shEpanorthosis
do I have to have a .ruby_version file?Epanorthosis
A .ruby-version file is to set the version for a user or a project. It's not strictly necessary but can be useful. If absent should go to the global default, if there is one.Fluoro
Remember to check with which ruby as to the one you're using, and look at echo $PATH to see that the chruby stuff is in there properly.Fluoro
so I added 2.1.2 to a .ruby-version file in my home directory, seems to be working now thanks everyone!Epanorthosis
If you solved it and understand how, add an answer here that explains it in a bit more detail. You're probably not the only one with this issue, and who knows, in the future you might forget and come back here to remind yourself.Fluoro
well, I don't know that I solved it per se. but it's a fix for now I guess. and okEpanorthosis
S
6

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
Sadden answered 26/2, 2016 at 14:4 Comment(0)
E
4

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.

Epanorthosis answered 24/2, 2016 at 20:51 Comment(0)
L
1

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

Liquidate answered 24/2, 2021 at 17:30 Comment(0)
S
0

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

Spondee answered 9/11, 2019 at 11:30 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.