Search code examples
ruby-on-railsrubyrvmrbenv

What do rvm and rbenv do under the hood to install Ruby?


For years, I've been dreaming about learning Ruby and the Rails framework. (Most of my development career has left me too busy to devote time to picking up a new language properly, but I'm making more time now.) I like the notion of being able to work with Ruby to develop quickly, but I'm having trouble understanding the Ruby installation process.

Each time I've encountered it, the Ruby installation process varies slightly. The two laptops I've used over the past several years have usually been running a then-recently released version of OS X, and all seem to ship with Ruby 1.8.7. Any modern version of Rails requires Ruby 1.9.x. So, I search the web and invariable bump into a post like this:

Use this awesome tool called rvm to manage multiple Ruby installs on the same machine.

or this:

rbenv is fantastic, and lightweight compared to rvm, use it instead.

Really? What is the Ruby install process doing, and why is it so complicated? By now I've gotten Ruby installed and running, but it seems like I've always had trouble with it. I'm genuinely confused and want to understand how Ruby lives on my system. What files are these configuration tools manipulating, and why can't I just do it by hand?

To put this a little differently: If I was RVM or rbevn, what steps am I taking to make Ruby work on a given system? Am I manipulating configuration files? Am I downloading source code and compiling it into an interpreter? Am I downloading a precompiled interpreter?


Solution

  • Rbenv and rvm manages multiple versions of Ruby. The question you link to describes how both of those tools do that (some people are of the opinion that rvm's integration with your shell is too heavyweight/magical ) . The ability to have multiple versions of Ruby coexisting nicely is a pretty big win. Historically there have been some disruptive releases (eg 1.8.7, 1.9.2) and so being able to migrate your development piecemeal or easily work on legacy projects has been very advantageous.

    The Ruby install process isn't that complicated at its heart - it's pretty much the usual download the source ./configure && make && sudo make install (RVM also has support for prebuilt Rubies). You can however tie yourself in knots (especially as a newcomer to Ruby)

    While some missing dependencies will just cause the Ruby build process to fail, others will just stop specific Ruby extensions from compiling (openssl or readline). You think you have a fully functioning Ruby until you try to run some code that uses those extensions. Others are even more subtle, for example if libyaml is not available then some versions of Ruby fall back to using syck as the YAML library instead of the more modern psych, with subtle differences.

    RVM just makes it very easy, compiling nearly any Ruby interpreter, version or patch level (jRuby, Rubinius, MRI etc.), with or without extra patches is only ever a single invocation. It's not doing anything very magical but it does remove a lot of friction.