Using Locomotive as your default Ruby
I'm hacking some Ruby this morning in TextMate and try to run a simple non-Rails application that uses ActiveRecord. ActiveRecord is an object-relational mapping library packaged as a RubyGems package that provides much of the magic of the Rails workflow, especially when generating scaffolding. I run the application and get an error when the script tries to import RubyGems. The error, of course, is because RubyGems isn't installed by default in the default installation of Ruby in OS X and that is what TextMate uses to run Ruby files.
Historically, the default Ruby installation in OS X has a bad reputation since it was apparently somewhat broken in versions 10.4.5 and earlier. Reportedly, this was fixed in 10.4.6 and later releases (I'm running OS X 10.4.8 at the moment) and I haven't had any issues with it myself (and it was recently reported that Leopard will ship with Ruby on Rails pre-installed.) The only issue I have with the default installation is that it is somewhat bare and doesn't include all the lovely goodies that come with Locomotive, the drag-and-drop OS X installer and administration client for Ruby on Rails. To get a similar set of goodies, you have to go through a lengthy and convoluted installation process. I don't do "lengthy and convoluted" unless I absolutely have to, so I decided to make the Locomotive version of Ruby the default for Terminal and TextMate. It's not hard to do at all:
- Right-click a Rails project in Locomotive and choose the Open Terminal command from the context menu, Locomotive opens up a bash shell and sources (runs) a bash script that sets up your environment to use the Ruby environment in the Ruby bundle in Locomotive. On my box, the script is located at:
/private/var/tmp/folders.501/TemporaryItems/61BE958C-12B0-476F-87D2-7BCCB0D71161-949-00000C80122F8DFF.environment.bash
The trick is to source this script from your bash profile script (the script that runs when you start a new bash session.)
- To start with, copy the script to a nicer location. For example:
cp /private/var/tmp/folders.501/TemporaryItems/61BE958C-12B0-476F-87D2-7BCCB0D71161-949-00000C80122F8DFF.environment.bash ~/.locomotive.environment.bash
- Next, update (or create) your bash profile script:
echo "source ~/.locomotive.environment.bash" >>~/.bash_profile
- Finally, remove the last line in the .locomotive.environment.bash script so that it doesn't change your working directory to the Rails project that you stole the bash script from. You can also add a message here to remind yourself that your Terminal sessions are using the Ruby environment in Locomotive and not the default Ruby environment. My final .locomotive.environment.bash file looks like this:
export RUBYLIB=/Applications/Locomotive2/Bundles/rails112.locobundle/i386/lib/r$ export HOME=/Users/aral export DYLD_FALLBACK_LIBRARY_PATH=/Applications/Locomotive2/Bundles/rails112.lo$ export PATH=/Applications/Locomotive2/Bundles/rails112.locobundle/i386/bin:/App$ echo "NOTE: Using Locomotive environment variables for Ruby."
That's basically all there is to it. Now, every time you start a new Terminal window, it will use the Ruby environment that's installed in Locomotive. To test this out, start the Interactive Ruby Shell (irb) in Terminal and type require "rubygems"
. Ruby should respond with true.
Comments
by David on 2006-11-05 05:13:17
by Duncan Beevers on 2006-11-09 04:11:12
by Mads on 2006-12-04 16:52:36
by ummm on 2006-12-07 02:02:48
by Chas. Porter on 2006-12-19 16:42:14
by aral on 2006-12-19 17:44:44
by Serge on 2006-12-23 03:54:15
by aral on 2006-12-23 11:11:16
by Chris on 2007-01-14 20:34:44
by Mark on 2007-01-26 20:58:12
by Alistair Holt on 2007-03-29 13:47:03
by My del.icio.us bookmarks for January 1st on 2007-03-30 00:35:49
by aral on 2007-03-30 09:45:06
by RubyNeo on 2007-04-07 01:59:01
by Phil on 2007-04-09 15:45:20
by aral on 2007-04-11 11:37:34
by Lanny on 2007-04-24 07:48:32
by nii amon on 2007-05-15 11:03:07
by aral on 2007-05-15 11:15:44
by Scott on 2007-07-26 18:51:12
by Ním on 2007-08-15 23:19:32
by links for 2007-08-07 « Amy G. Dala on 2007-08-07 14:17:17
by Alex Satrapa on 2007-09-24 01:34:37
by SWX Ruby Alpha Released: SWX RPC for Ruby on Rails at Aral Balkan on 2007-09-17 15:45:16
by Holly on 2007-09-20 12:17:47
by Alex Satrapa on 2007-09-21 01:55:17
by Aral on 2007-09-21 15:49:03
by ugg boots on 2010-12-14 03:45:19