Last week I wrote about how search affects programming language design, pontificating about how easy it is to find Ruby/Rails “soft documentation” using Google (or another search engine), and how practical and to-the-point that “soft documentation” is once found. In that post I also praised the swift and united adoption of RVM+Bundler by the Ruby/Rails community as an example of a programming ecosystem growing with its users.
Flash forward to this week:
I needed to write a standalone Ruby script. Once I started, I realized that I didn’t know how to set up my Ruby environment outside of the safety of the Rails projects I have been working with so far. In fact, I realized that I couldn’t even remember the exact relationship between gems, rvm, and bundler. To my surprise, I was still kind of confused after 5 minutes of searching around on the Internet using Google.
So, in order to contribute back to the ecosystem I wrote about last week, here is the “RVM + Bundler in 5 Seconds” high-level introduction I wish I would have found. If you are newbie trying to orient yourself to Ruby/Rails, I hope you read this and it saves you four minutes and 55 seconds of Googling around on the Internet:
RVM is a program that lets you switch between different rubies and gem environments while you are working. The gem environments are implemented as gemsets, which are named sets of gems. (The gemset may additionally specify the versions of the individual gems in the gemset.) RVM introduces the .rvmrc file that automatically switches you between different Ruby versions and gemsets, depending on what folder you are in. RVM does not help you install or maintain your gemsets, you have to do that yourself or with bundler.
Bundler is a tool that automates the installation and maintenance of the gems in gemsets. Bundler introduces the .gemfile file that defines the gems (and gem versions) in the gemset.
Note: bundler and rvm are independent. You could use rvm gemsets without bundler (just “gem install x”), or install gems using bundler without involving gemsets if you wanted to.
If you have one global Ruby environment and don’t intend on changing it, you might be able to live with just using the “gem” command.
If you have multiple Ruby environments (eg you are working on multiple projects from Github) you can use RVM to switch between the different rubies and gemsets…
…but you also want to use Bundler to automate the installation and maintenance of the different gems (eg you just have to checkout the project from Github, and run the “bundle” command in the project directory and everything you need will automatically install).