rvm > virtualenv
In my journey of computer languages I’ve gone from ruby to python and am now coming back to ruby (and rails) again.
In my python foray I became enamored with a little tool called virtualenv (and virtualenvwrapper). What it allows you to do is create lots of mini virtual environments for python projects. The environments can have custom pip packages and even a specific (non-system) python. Everything is contained within the virtual environment, so you don’t (and shouldn’t) sudo to install packages. This proved extremely handy for working with projects that may want specific and conflicting versions of libraries. Or for doing things like testing a new version of django.
Starting back with Ruby and Rails I was concerned that I’d be leaving that ability to spin off customized environments at a whim behind.
I shouldn’t have been concerned. The ruby community has it solved (with additional features and a nicer interface, ahh ruby) with the fantastic rvm
With rvm I can:
- install new ruby versions without touching the system ruby
- have my environment use a specific ruby version by default
- spin up little environments with a given ruby version (without even the slight virtualenv gymnastics to bring up a specific python version)
- create .rvmrc files in project directories that will silently switch my environment to that project’s environment
That last one is key, and not present in virtualenv. That means I can have (say) three projects, each with their own custom environments. When I cd around rvm will silently load each environment as it detects that one has been specified for that directory and then switch back to the environment that had been loaded when I cd out.
Spinning up a new environment is easy!
# 1.9.2 specifies the ruby version
# everything after @ is the name of the gemset
$ rvm gemset create 1.9.2@projectawesome
Loading an environment is easy too.
# this would also be the entirety of the .rvmrc file for project awesome's directory
$ rvm 1.9.2@projectawesome
Ah yeah. So bring it, Rails 3. I’ve got an environment just waiting for you.
Thanks to Sirupsen for his excellent tutorial: Get started right with RVM