blogstrapping

RVM Day

You may have noticed that I'm making an effort to do more Rubinius-related stuff today (Friday, 05 August 2011) because it's rbx day. I've been doing stuff with Rubinius off-and-on anyway, ever since first giving Rubinius a try, but this is a great excuse to start doing more.

One thing I have not done that I decided to do today is start using the Ruby Version Manager, or RVM, making this RVM Day as well as RBX Day. I installed RVM for the first time, and am now trying to get used to using it. So far, it's pretty slick.

The downside so far is that it is not very clearly explained anywhere -- and not just it, but the Ruby installation options that come with it. I don't recall where, but I saw an example somewhere that suggested using rvm install ruby-head for some reason, but I do not recall it saying anything about why rbx-head rather than rbx, for instance. I imagine rbx-head must give me up-to-date rbx from the current state of the Rubinius project, but beyond that my guesswork does not provide me much in the way of specifics.

I have not yet found a single point where one can go to get a quick start with RVM that provides understanding as well as examples, thus resulting in my choices being either by-rote cargo cult installation and use or hours of sifting through help documentation and pestering people in email or IRC for details.

I know that RVM's popular use is a relatively recent thing, and of course I grant some leeway for that fact; people have likely just not had time to bring the quality of tutorial documentation up to par with the needs of new users of RVM, and it is totally understandable. I am just pointing out where that deficiency exists. Unfortunately, I am still so much a novice with RVM that I am not qualified to fill in the gaps in documentation.

Some Nascent Tutorial Stuff

Before you start just blindly following my examples below, I recommend you actually read the whole thing, and check out the linked pages. I know this is kind of a lot of reading, but this is not in fact a fully cleaned up tutorial, ready for prime time. It is more of a rambling explanation of my experiences getting started with RVM, including explanations that might be of help to other people just getting started. If you have a better (more succinct) source of information than this, you should use it -- and you should tell me about it. I have a contact page here at blogstrapping you can use to tell me about any tutorials and explanations you've found.

If I do not find something suitable before I get around to it, I may write up a complete startup tutorial at some point when I feel sufficiently well educated about all the relevancies of RVM to do so. For now, though, this is what you get from me.

Installing RVM itself employs this incantation:

bash < <(curl -s https://rvm.beginrescueend.com/install/rvm)

The -s is "silent mode" for the curl command. Curl itself is basically a download tool (though a fair bit more, as well). By issuing that parenthesized curl command, you are effectively telling it "give me the file at the indicated URI, and don't tell me any details". Obviously, the -s can be omitted if you want more information about what is going on. If I am not mistaken in my assumption, the redirects before the opening parenthesis basically tell your shell that instead of saving the file somewhere, it should send its contents to bash for execution. This makes me wonder if it would work with other shells than bash, such as sh, but I have not investigated the matter.

The Ruby Version Manager - Installing RVM page actually suggests a complete script for getting up and running with RVM:

#!/usr/bin/env bash

# Install git
bash < <( curl -s https://rvm.beginrescueend.com/install/git )

# Install RVM
bash < <(curl -s https://rvm.beginrescueend.com/install/rvm)

# Install some rubies
source "$HOME/.rvm/scripts/rvm"
rvm install 1.9.2,rbx,jruby

The 1.9.2,rbx,jruby part at the end of that pretty obviously seems to indicate that RVM should install the MRI/YARV implementation of Ruby 1.9.2, the Rubinius implementation, and the JRuby implementation. Edit to suit. Of course, I wanted to try something a bit more nuanced that I found elsewhere; the following example from beginrescueend.com's Ruby Version Manager - Rubinius:

rvm install rbx -- --enable-version=1.9,1.8 --default-version=1.8

Also, I already have Git installed, so that part seemed unnecessary. As such, I just ran the command using curl to install RVM, and used this rvm install command. Unfortunately, it did not work as advertised.

Rather than doing what one might expect -- installing Rubinius with support for Ruby versions 1.9 and 1.8, defaulting to 1.8 -- it errors out. Apparently, the --enable-version and --default-version options are not actually supported by whatever tool actually supports them. I may investigate this further, but for now the error messages I received did not offer much in the way of useful information for figuring it out. At that point, I just eliminated everything after rbx and ran this much shorter command to install Rubinius via RVM:

rvm install rbx

Once you have your Ruby version of choice (rbx -- right?) installed via rvm, you can execute a program using that version pretty easily:

rvm rbx program_name.rb

What else can you do? The output of rvm help is a gigantic wall of text that can be a little difficult to wade through. Spend hours on it?

Well, I suppose I could have done that as the next step in my own odyssey of learning about RVM, but it would be nice if there was something a little quicker and easier to give me a boost. In fact, the situation is worsened a bit by the fact that rvm rbx does something surprising, in that it fails to start an instance of irb, the Ruby REPL, when run without a program name argument. This is surprising because via other means I have used to install Rubinius just executing rbx with no arguments would start the REPL. In addition, while managing various different Ruby versions simultaneously with a centralized system like RVM would hopefully make things easier for admin purposes, I am not really sure this is a huge win when every time I need to run a program I need to prepend the rvm command to the command I would otherwise use.

Luckily, that is not actually required. With some prompting from j\ey` in IRC, I figured out the value of this:

rvm use rbx

When j\eymentioned this, I immediately entered thervm help usecommand to get *specific* information about theuse` command for RVM. The results:

M-bM-^HM-4 rvm use [ruby-string]

Setup current shell to use a specific ruby version.


For a list of currently install ruby string please run

  rvm list

Please see documentation for further information:

  http://rvm.beginrescueend.com/rvm/basics
For additional information please visit RVM's documentation website:

    https://rvm.beginrescueend.com/
If you still cannot find what an answer to your question, find me 'wayneeseguin' in #rvm on irc.freenode.net:

    http://webchat.freenode.net/?channels=rvm

Well, this helps a lot. Specifically, this very succinct line -- the second line of text in that help output -- explains quite clearly what rvm use rbx will do for me:

Setup current shell to use a specific ruby version.

Within that shell, but not others, RVM establishes the indicated rbx install as the Ruby implementation that should be used every time I enter a ruby or irb command. Other shells will use whatever is the system default, but that one uses what I have just told it to use. This is, in fact, pretty slick.

Conclusion

So far, so good. I just wish there had been a nicely formatted page somewhere obvious explaining all of this, plus the information I still do not know about what has gone before, in a clear and helpful manner. At least trial and error, in the cases where I have used that approach to muddle through so far, has not resulted in screwing up something on my system yet (as far as I'm aware).

Perhaps, once I get some more experience and understanding with this stuff, I'll flesh out and clean up this explanation for an RVM tutorial page. Then, maybe I'll try providing it to the people maintaining RVM so they can put it somewhere obvious enough that people like me who come along in the future can gain the benefit of my experience.