8r4uog
Last Updated: September 16, 2017
·
2.585K
· artchang

Install chruby to replace rvm on OS X

RVM to chruby on OS X

For various reasons, I chose to drop rvm and move onto chruby.

Removing RVM

  1. rvm implode
  2. gem uninstall rvm
  3. Remove references to rvm in any .bashrc, .bash_profile, .profile, .zprofile, or .zsrsh files

Installing chruby using homebrew

I use Homebrew whenever I can. Learn more about Homebrew here

  1. brew install chruby
  2. Add source /usr/local/share/chruby/chruby.sh into your ~/.bashrc file
  3. Add source /usr/local/share/chruby/auto.sh into your ~/.bashrc file as well. This will tell chruby to automatically switch to the correct ruby version when you change directories into something like your rails app's root directory. It does this by looking up a file called .ruby-version. If you don't have that file, create one at the root of your rails project or wherever your ruby scripts are located. Note: you'll have to follow the ruby-install steps to get the right ruby versions.
  4. echo "source ~/.bashrc" >> ~/.bash_profile
  5. restart terminal

Installing ruby-install

The ruby-install gem is what I use to install ruby versions that chruby then picks up from the ~/.rubies directory automatically.

  1. brew install ruby-install
  2. restart terminal

Installing ruby versions

RVM installs the ruby versions for you, but chruby only helps you switch, which is why we will use the ruby-install gem.

  1. ruby-install ruby This will install the latest stable version of ruby into your ~/.rubies directory. If you have a .ruby-version file at the root of your rails app, chruby will find it and switch for you automatically or if/when you specify.
  2. ruby-install ruby 1.9.3 is an example of installing another version of ruby.

Conclusion

That's it. Using chruby is pretty simple, as it doesn't need shims and is easy to follow and fix if you need. It's comparable to rvm and rbenv, but the simplicity is what I like.

2 Responses
Add your response

14587

Thanks. It helps a lot.
How can I use specific version of rails with chruby ?

over 1 year ago ·
28647

Thanks for the post. Quick question, what's the proper way to switch the ruby version when you're in another project?

over 1 year ago ·