I am interested in how RVM and rbenv actually work.
Obviously they swap between different versions of Ruby and gemsets, but how is this achieved? I had assumed they
So to summarise the excellent answers above, the main practical difference between RVM and rbenv is when the version of Ruby is selected.
rbenv:
rbenv adds a shim to the start of your path, a command with the same name as Ruby. When you type ruby
at a command line the shim is run instead (because it is also called "ruby" and comes first in the path). The shim looks for an environment variable or .rbenv_version
file to tell it which version of Ruby to delegate to.
RVM:
RVM allows you to set a version of Ruby directly by calling rvm use
. In addition, it also overrides the cd
system command. When you cd
into a folder that contains a .rvmrc
file, the code inside the .rvmrc
file is executed. This can be used to set a Ruby version, or anything else you fancy.
Other differences:
There are of course other differences. RVM has gemsets out of the box, while rbenv requires just a little more hacking (but not much). Both are functional solutions to the problem.