This lesson goes into greater detail about using the tools
chruby, which are tools for managing Ruby versions for Mac OS.
chruby are not available for Windows users. Windows users should use Ruby Version Manager, a Ruby version manager that is compatible with Windows. However, as long as Windows users have installed
Ruby+Devkit 2.6.6-2, there should be no need for a version manager for the Ruby/Rails curriculum. Reach out to your instructor if you have any questions.
In an ideal world, developers would always use the latest, most perfect version of a language. In reality, updating older projects is often a huge pain point, especially in very large or dated projects. The version of Ruby you use for projects now will likely be different from the one you use a year from now, which in turn will be different from the version you use five years from now. However, you may still need to maintain past projects (especially if they're work-related), which means you'll need the ability to switch between different versions of Ruby in your personal environment.
This issue may also come up at Epicodus if the version of Ruby that's installed on your personal machine is different from the version installed on Epicodus computers. You shouldn't be expected to downgrade the Ruby version in your global environment in order for your projects to be compatible with Epicodus machines; however, you should be able to use the same version we use at Epicodus. After all, it would be poor etiquette in the workplace to expect your work to use your version of Ruby instead of the other way around!
Fortunately, there are many Ruby version managers that manage this job, including
RVM is the most widely-used but has its share of problems and frustrations. We'll focus on
chruby because it's lightweight and easy to use.
We'll need to install two packages. These packages should never be installed on Epicodus machines, which already have the correct version of Ruby installed on them. These lessons are intended for your personal environment - and to ensure that your personal environment matches the one in the curriculum. Also, if you followed along with the installation instructions in a previous lesson, you do not need to reinstall these tools.
chruby will allow us to switch between different versions of Ruby.
ruby-install will allow us to install different versions of Ruby.
We can install both with brew:
$ brew install chruby $ brew install ruby-install
ruby-install is set up, we can use
ruby-install in the command line to install new versions of Ruby. For instance, if we wanted to add Ruby 2.4.1, we'd run the following command:
ruby-install ruby 2.4.1.
chruby, we'll need to do some minor configuration to our shell, whether bash or zsh. The configuration files for our shells live in our home directory. If you are using bash, locate a file called
.bash_profile. If you are using zsh, locate a file called
.zshrc. We can open it with VS Code:
$ code ~/.bash_profile
$ code ~/.zshrc
Next, we'll add the following line to the end of the
source keyword informs our shell to find the specified file and then execute it in the current shell. A
. can also be used in place of source, so
. /usr/local/share/chruby/chruby.sh also works. (Note that the space between the
. and the
/ is very important.)
If you'd like to specify a default version of Ruby for the shell, you can add the following line to
In the above example, Ruby 2.6.5 will be the default. It's recommended that you set the default to match the Ruby version at Epicodus (at least while you're a student) to avoid potential version mismatches or issues on code reviews.
Finally, to see which versions of Ruby are installed in your environment, you can type in the
$ chruby ruby-2.4.1 * ruby-2.6.5
You can also type in
$ ruby -v to confirm which version you're currently using:
$ ruby -v ruby 2.6.5p57 (2018-03-29 revision 63029) [x86_64-darwin15]
Finally, to change between Ruby versions, you can type
chruby followed by the version you'd like to switch to. For instance:
$ chruby ruby-2.4.1 $ ruby -v ruby 2.4.1p111 (2017-03-22 revision 58053) [x86_64-darwin15]
Lesson 6 of 8
Last updated October 13, 2021