
A Tale of Two Rubies, Part I
Managing Rubies with RVM
In a typical ruby shop, there’s a strong likelihood that you’ll come across RVM or rbenv for managing ruby versions. These tools are useful to juggle different projects, where different versions are required.
If you have different projects that use the same ruby, but have a need to keep gems separated, you can segregate gems using gemsets. RVM has direct support for gemsets, and rbenv can use rbenv-gemsets extension.
This is a two part story, one for RVM (Ruby Version Manager) and another for rbenv.
The Tutorial
We’ll create two pretend projects that mimic a potential real-world use cases:
- Fearless – Rails 5, Ruby 2.4
- Empower – Sinatra, Ruby 2.3
RVM Install
The first step is setting up RVM for the current user:
Rubies and Gems
Here we can install some ruby and gems for our projects:
Project: Fearless
This is a pretend web project using a recent version of Ruby on Rails 5 on Ruby 2.4:
The previous version of the project used ruby 2.3.6 and rails 4.2. In a real project, the .ruby-version
to reflect current ruby used in the project. The .ruby-gemset
may be updated as well depending on your environment.
Project: Empower
This is a pretend web microservice project using earlier version of Sinatra 1.4 running on Ruby 2.3:
Testing Project Rubies
With steps above, you can now easily switch between ruby versions and gemsets by simply switching into those directories. RVM will auto-configure the environment for you:
$ cd ${HOME}/projects$ rvm use 2.3.6
$ ruby -v
ruby 2.3.6p384 (2017-12-14 revision 61254) [x86_64-linux]
$ gem env home
/home/vagrant/.rvm/gems/ruby-2.3.6$ cd fearless
$ ruby -v
ruby 2.4.3p205 (2017-12-14 revision 61247) [x86_64-linux]
$ gem env home
/home/vagrant/.rvm/gems/ruby-2.4.3@fearless20
Conclusion
I hope this introduction was useful regarding managing ruby and gemsets. Next article, I will cover Rbenv and why gemsets are not used, and even discouraged.