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).

5 comments:

Anonymous said...

hello, i'm really new to linux and ruby but I have no other choice, can you post the complete code in launcher so I can have a better idea about what to do!

thanks

Ian said...

Hi Anonymous,
OK, it's pretty straightforward. The steps are:


1. right-click on the panel where you want to create the launcher, and select "Add to panel ..."

2. In the "Add to Panel" dialog, click the first entry "Custom Application Launcher" and then click the "Add" button.

3. You should get a "Create Launcher" dialog pop up. Enter "Eclipse" as the name, and /bin/bash -ic /home/ian/dev/java/eclipse/eclipse as the command (but obviously you have to change /home/ian/dev/java/eclipse/eclipse to the location where you installed your eclipse)

4. [optional] If you like, change the icon to something other than than the weird spring thing (but this is only cosmetic!)

5. Click OK, you're done

At this point, you should have a button on your launcher that you can click on to run eclipse with access to rvm.

Anonymous said...

Ran into this exact problem and immediately found this post.

Thanks a million!

Mahesh said...

Hey Thanks,
This is a better way of doing it. I had the same problem and i was running Eclipse from the terminal.

Optisolbusinesssolutions said...

Impressive work here, loved the valuable information. Thanks for all your efforts. ROR Development Company