Thursday, January 27, 2011

Ruby, rvm and Eclipse

I've switched to using rvm for all of my ruby development. Rvm makes it trivial to have multiple copies of ruby installed side-by-side, while trying to do that using apt-get was proving a big headache. It has brought one minor gotcha though: rvm runs a script from the .bashrc or .bash_profile to set up the environment so that a current – default – version of ruby is always selected. If the .bashrc isn't run, no rvm and hence no ruby. I have my Linux desktop set up so that I have a quick-lauch button for Eclipse on the toolbar docked to the edge of my screen. Launching Eclipse from there doesn't invoke .bashrc for the containing shell, hence Eclipse wasn't seeing my installed rubies. I could point to the actual location of the ruby interpreters, but my applications weren't able to load any gems.

My solution was to force Eclipse to run in a shell which does load .bashrc. This is simply achieved by the -i and -c flags for /bin/bash: i to force an interactive shell (which loads .bashrc) and c to run a specific command (Eclipse in this case).