Post

Installing Ruby using chruby and ruby-install

Every Ruby developer will most likely be using a Ruby version manager. The most popular ones are: RVM, rbenv, and chruby. You can use whatever makes you happy. I went with chruby, and I’m happy with it.

What is chruby

chruby is a command line tool that lets you switch between different versions of Ruby. It allows you to change between them manually, or it can change the version for you automatically, as you navigate between project folders.

It is only capable of switching between versions, not installing them. The chruby maintainer has another one to get it installed, called ruby-install.

What is ruby-install

ruby-install is also a command line tool that one can use to install many flavors of Ruby. Yes, there are many of them: Ruby, JRuby, TruffleRuby, and mruby. Focus on the first one, it’s the most popular, and written by Yukihiro “Matz” Matsumoto, Ruby’s creator.

Getting chruby and ruby-install installed

Both tools are maintained by the same person, so they follow the same installation pattern, even the README files are very similar. They are meant to work together.

chruby vs ruby-install README file

Follow along with the installation guide on their README, for ruby-install here and for chruby here. Usually, I just go with downloading the tarball via wget and compiling it using make install.

Note (2024-11-22): I had an issue installing it on WSL Ubuntu 24.04 with zsh, and ended up having to manually add the following lines to my ~/.zshrc file.

1
2
source /usr/local/share/chruby/chruby.sh
source /usr/local/share/chruby/auto.sh

How to use them together

To get the latest version of Ruby, run:

1
ruby-install --update ruby

To get a specific version (which is very common), run:

1
ruby-install ruby 2.7.5

Once you have ruby (the command line tool) installed, it is time get it on your current PATH (selected) using chruby.

List the installed version using:

1
2
3
chruby
   ruby-2.7.5
 * ruby-3.0.3

The * next to the version means that it is the selected version. If you run ruby --version, you should be able to get that same version.

To switch to a specific version, run:

1
chruby ruby-2.7.5

The chruby tool will not list the version of ruby that comes pre-installed with your OS, but you can still switch back to it using:

1
chruby system

Automatically switch between versions

chruby will look for a file named .ruby-version every time you navigate between folders. If the file can not be found on the folder, or on one of its top-level directories, chruby will look for one on the home directory (~/).

Give it a try using:

1
echo "ruby-3.0.3" > ~/.ruby-version

Conclusion

I hope this post helps alleviate some of the pain that it is to get started with a working (and functional) Ruby development environment.

This post is licensed under CC BY 4.0 by the author.