RVM, which is a rather heavy-weight solution to gem conflicts, has been chafing on me so here's a tutorial on getting going with rbenv instead, which just manages Ruby and leaves gem version dependencies to Bundler.
NOTE: Just because I'm switching, doesn't mean rbenv is necessarily "better" than RVM. I'm often switching between technologies to try them out and I could end up hating rbenv in a month (though I don't anticipate it). RVM is still a fine piece of work and you'll get along with it just fine.
If you have RVM installed, you can delete it easily with:
rvm implode
Note that you may have to delete the line from your .bash_profile
/.bashrc
that loads RVM.
Installation is fairly straightforward, more so if you are on Mac but not bad if you're on Linux. Follow the tutorial to get it installed.
rbenv is very lightweight, so much so that it actually doesn't even install ruby for you, you have to install it from the commmand-line yourself! Bleh! Luckily, rbenv supports plugins, so there's all sort of good ones I'll show you here.
rbenv-build is a gem that manages installs for you, so you can just do something similar to rvm like rbenv install 1.9.3-p327
rbenv-bundler makes it so you don't have to prepend all your commands with bundle exec
to load up the right gems. (This was my #1 complaint with not using RVM. Finding out that there were gems that fixed this is what led me on my quest away from RVM in the first place.)
Once you have these two installed, you should be ready to rumble in your projects. Install bundler with gem install bundler
, then rbenv rehash
(explained below), then bundle install
again you're ready to rumble!
rbenv-sudo is not strictly necessary, but really nice if you're deploying to your own server where you need to run the webserver as root. Root's PATH doesn't know about rbenv, so rbenv-sudo
monkey patches root's PATH to have rbenv's ruby available. Really nifty, RVM has something similar with rvmsudo
.
Note that each of these plugins install the same way, you just run a git clone and you're done.
Luckily, there's only one real gotcha, and that is to remember to run rbenv rehash
each time an executable is installed that you want access to from the command-line (such as bundle
, rspec
, foreman
, rails
, etc.) Luckily this doesn't happen too often, but just often enough to make it annoying. Anytime you install a gem, then attempt to use it and you get a "command not found", just let that be a reminder to run rbenv rehash
.
I prefer this to having to create .rvmrc
files for each project and manage separate gemsets, which I found more annoying (and really confusing to beginners).
I recently found this awesome gist that gives you a script for installing a faster version of Ruby, with about a 30% speedup, which is significant (and accurate in my testing). Again, just a one-liner you copy and paste. Be sure to read the instructions though to make sure you have rbenv
and ruby-build
installed first. Win!
I also ran into this cool gem called zeus that preloads your entire rails environment, and reloads anything that gets changed (including third-party gems). It's like spork
on crack, if you're familiar with spork
. It renders spork
useless, as far as I can see since it works for everything, not just testing. Boot up a console, server, generating models/controllers, you name it. A great find, indeed. The one downside I've had is that sometimes, when I quit certain processes (like the server) with ctrl+c
, my terminal session will stop responding and I have to close that window and open a new one. It only happens sometimes, but I'm willing to deal with it for the awesome speedups.
If you find any other great tools you think the group would benefit from, be sure to let me know!