Creating a Rails Development Environment on Mac OS X

I’ve been writing Ruby on Rails apps for several years now, and both at my day job, and my contract work, I’ve been utilizing a modified version of the Locomotive Project from Ryan Raaum. I rebranded it as “MiCodaLoco” for our use, and modified it to be a little more modular for it’s startup environment, moving the MacPorts distribution it used to a central folder and out of the “bundles” it used for each Ruby and RubyGems environments.

It worked out quite nicely for several years. But it was a complete pain to rebuild ruby and rails versions, because I never took the extra steps to automate the bundle building process. I always had grand plans to create a “debug” button as well to launch mongrel (or thin, about the only change I’ve made in the last year has been to start thin instead of mongrel for one of our apps that ran into a problem with Rails 2.3.8 and/or Rack changes and cookies and mongrel) in debugging mode for ruby-debug.

I had poked my way around the Objective-C app, and I understood where to make modifications I needed, but I didn’t really understand how the app was put together (and parts of it were pre-Interface Builder and had code created interface that I still don’t totally grok, even after a week long iPhone training that had enough Obj-C in it to make me dangerous).

Best-laid plans being what they are, I never did update it, and it was time to move on. With a Rails 3 and possibly a Ruby 1.9 update in the next six months to year for all these apps – I wanted to spend more time on that than learning Cocoa. So I needed something new.

Enter Homebrew, RVM, and Passenger standalone.

Homebrew

So, I’ve been a Fink, then DarwinPorts MacPorts user forever, and would recommend it to anyone to get open source packages (like wget, or wireshark) that don’t come already with OS X. But sometimes suggesting it to your colleagues just to install something to facilitate something else doesn’t always go over well.

Enter Homebrew. Because Homebrew uses a lot of of what’s already there in OS X instead of installing it’s own versions, it’s faster to get the packages you need (with the risk that something is broken with an OS update, but I haven’t seen something like that in a while with 10.5/10.6 on Intel). And in our case, we only need the mysql client libraries for the mysql gem, and the imagemagick libraries for the rmagick. And wget. Because everyone needs wget.

It’s easy to get started, just follow the instructions (The system admin in me recommends you look at the executed ruby script first – but I know you won’t).

Oh, you need Xcode. You do have Xcode installed right? Even the designers need it for the iPhone emulator. Trust me.

In our case we needed to

brew install mysql
  • which installs mysql server, but we use MAMP for that, so it’s just for the libraries (in theory, you probably can just link the mysql gem against the MAMP libraries if you use MAMP. But I don’t want some MAMP upgrade where I put it in a different path wreak havoc on that). We also needed to

    brew install imagemagick

. And if you are testing your caching code and use memcache,

brew install memcached

You might need something else installed, but we haven’t as of yet.

RVM

RVM is everything I ever wanted doing multiple Locomotive/MiCodaLoco bundles to be, and then some, with the added bonus that somebody else does it.

RVM lets you run multiple rubies and multiple gemsets per ruby installation, making it really convenient to not only switch between them for testing and dev purposes, but also just to have an effective development environment.

RVM’s documentation is very comprehensive, though it can be a little tricky to get started. Here’s what we needed (after installing RVM):

rvm install ree                           # I use ruby enterprise edition - version 1.8.7 on our, ree is a shortcut string for this version - see "rvm strings" for morervm gemset create busterleague # creates a gemset for a person project of minervm --default ree@busterleague  # sets my default ruby to ree and the default gemset to busterleaguervm use ree@busterleague        # sets up the session to use ree and the busterleague gemsetgem install rails --version=2.3.10  # still at rails 2gem install passenger               # passenger v3gem install ...                           # rest of gems

As a convenience – because you like will end up shifting between rubies – or at least gemsets – create some bash aliases to make that easier (Locomotive/MiCodaLoco had a “open terminal” command for each project that automatically put one into the right bundle environment and the working directory for the project, these aliases replace that as well).

Here’s mine for my work, contract, and personal projects (I put my working directories in a “dev” subdirectory to my home directory)

alias rubydevprompt='PS1="rubydev:W ($(~/.rvm/bin/rvm-prompt i v g))$ "'alias smallwonder='rubydevprompt && rvm use ree@trixietracker && cd ~/dev/tt/smallwonder'alias darmok='rubydevprompt && rvm use ree@extension_production && cd ~/dev/extension/darmok'alias dega='rubydevprompt && rvm use ree@extension_production&& cd ~/dev/extension/dega'alias busterleague='rubydevprompt && rvm use ree@busterleague && cd ~/dev/personal/dmbdraft'

I can then switch between them at ease, add more to do things like start passenger (more on that below), or to use development gemsets, like rails 3 (and even add git commands to make sure I’m in the right branch (ala rails 3)

rvm-prompt has a nice documentation page

Passenger

Finally, I use Passenger in standalone mode running on an arbitrary port to deliver the dev versions of our apps (actually I use passenger everywhere, currently running under Apache, it’s made my system admin life much easier than other rails environments).  After installing passenger, just run the “passenger start” command, and it will self-install and configure a version of nginx that it uses to do this.

As a convenience, I’ve created a ruby script that starts passenger with a set of default parameters – which can be overridden by a yaml configuration file – or from the command line. I called this “script/devserver” to distinguish it from the rails webrick “script/server” command.

You can see a version of that devserver script at github

What I probably need to do is go back and have a debugging option that would start webrick, mongrel, or thin in order to use it with ruby-debug (since Passenger 3 isn’t really setup to support ruby-debug)

[Update] You probably want this link to the devserver scripthere’s why.

Software feature shout-out

As a software developer, I’m keenly aware that the tools we create both empower and frustrate those that use them. I guess after what feels to be four or five internet lifetimes by now, I’ve gotten used to adapting to the features – and the quirks – of whatever software packages I use myself.

My development, both at work, personal, and contract deals with MySQL. And for a long time, I’d run a local instance of phpMyAdmin so that I could get at the DB. And I’m grateful for phpMyAdmin – but most of the time I just need something that will help create db’s and users, and give me a nice interface and history for queries.

And that’s when I started using Querious for the Macintosh. If it all it did was give me a native application to do the routine stuff, and a query window, I’d be fine with it, and it would be worth the $30.

One feature in particular though that stands out, and that has come in amazingly handy is their CSV import. To assist some friends and colleagues of mine in a simulated baseball draft league, I wrote a web app that manages the baseball draft – and allows custom rankings of players for individual league owners. Importing that data though involves trying to get an excel spreadsheet of stats into the database – and for anyone that’s done this, you know it can be a major pain to line up stat columns and types with the db columns.

Not so with Querious. The app has what might be one of my favorite features in a software program ever – a drag and drop association of import columns to db columns:

I don’t have to do this a lot, but man when I did, this came in extremely handy.

The application also has the built in ability to create ssh tunnels for connecting to remote systems, which is also an extremely handy feature.

It’s a great feature, and a great app, and one of the most useful tools I own. A big thanks to Araelium for developing it.

First TimeMachine Restore

timemachine.pngI did my first TimeMachine restore today. I tried out Firefox 3 Beta 1 – and decided that I wasn’t quite ready for it. So I restored my Firefox Profile from this morning before I downloaded and started running FF3. Click the TimeMachine icon, pick the date/time, navigate to the folder, click restore. And voila! it worked. It actually worked. And it prompted me if I wanted to replace the current profile directory or keep both.

That might have been the easiest restore on any platform I’ve ever done.

It really is about conversations

VMWare developer Ben Gertzfield did a really awesome thing a few days ago, he commented on my blog. What’s so cool about this is that Ben is a VMWare Fusion developer – and I had a seemingly throw-away line in that post that “VMWare fusion is not as user friendly as Parallels” – and Ben asked about how they could improve VMWare Fusion.

That’s INCREDIBLY cool. The man is doing Google Blog searches or has an Alert set up, or whatever it might – and he’s actually going out and asking real questions about how to make the product better. That’s awesome. My colleague Ben MacNeill does the same thing and I’ve always been impressed by it (and thankful to be working with Ben because of it). Along the same lines – I received a comment from Marc Hedlund (or someone helping Marc do this), one of Wesabe’s founders about using Wesabe. I’m still a little squicked out by doing my combined finances in a web application – but marketing like Marc/Wesabe did with that comment goes a long way to influencing me to trying it out. It’s about reaching your customers where they are.

It’s an old saw, but marketing like this turns customers or potential customers into fans. Like Kevin says you have to be the ball.

Ben, VMWare Fusion was already a great product, I’ve had zero problems with it running it the last few days, using both Windows XP and Ubuntu. I’m a longtime VMWare user on other platforms, and I’ve used Parallels since just after it came out – and I’ve been happy with it too. But that single comment, combined with the energy that you really show for the product in your blog (even if it was setup for that express purpose), helped cement my continued use of Fusion for a long time (okay, just don’t like the product turn to crap 🙂 ).

Ben asked for a few observations about the usability – and I spent a fair amount of time with both products yesterday and today trying to figure out some specifics about my throw-away line. I’m probably a terrible poster child for usability – I couldn’t design a good UI if I wanted to – and there are some things I am too nerdy about to judge other UI either.

This is also done using the Fusion 1.1 Release Candidate. I think that’s fair to evaluate, but it isn’t an official release, so those reading this should keep that in mind.

My take-away is that the settings interface is really at the core of my “user-friendly” comment.

The first general impression I have is completely subjective. But I like the way that Parallels handles the vm “object” (for lack of a better term) – I don’t like the Parallels “picker” – but once a VM is picked – I get a window with the state that the VM is in – and a list of settings and controls:

parallels-vm.png

It’s not real clear from the Parallels window that I can click on the configuration and make changes, but if I do – I get what I consider to be a better interface for browsing those settings:

parallels-vmsettings.png

If I click on “Settings” for the VM in Fusion, it will bring the display window for the VM – and show the settings as a property sheet.

fusion-settings.png

This is really subjective – but I think the Parallels way of doing it is more understandable – and better “information at a glance” – I shouldn’t have to have a display window (which is black if the OS in the VM is “off”) pop up to manipulate the settings for the VM – and the summary views are nicer I think.

To be fair, I hate property sheets. So that’s part of it I think. And whether this qualifies as “User Friendly” probably depends on the user.

Something that I don’t think is as subjective – shows up when changing the settings for something like the Shared Folders – this is where the Parallels dialog has an advantage (p.s. that drag and drop of files between fusion and the finder is FANTASTIC, really great implementation). I think shared folders in general needs some work – I actually had some trouble with the text of .hostShared Folders and trying to figure out what that really meant in terms of getting access to resources. Focusing on the UI though, this:

parallels-folders.png

is preferable to this:

fusion-folders.png

I actually had to go to the help to figure this out. I completely ignored the “+/-“ controls on the left because they didn’t make contextual sense to me. Having them there implies that I’m going to click them to add a new “setting category”- not a sub item for the categories – placing them on the right, and limiting the list to the context of whatever I’m focused on would seem better to me.

I also would like to see all my shared folders at a glance on the right rather than having to click each one on the left.

(actually I kind of like how Parallels does it by default – mapping a volume on the Macintosh side to the entire disk for the VM – although that seems broken in Leopard – perhaps due to some issue with the version of MacFuse that it uses, at least from the messages in my console log)

These were some of the things I focused on. I think there are little things like this elsewhere in the settings, and in the menu layouts. Having a general usability walk through of the settings sheet in particular by someone that that is a real usability wonk would do wonders I think. The settings work – I was able to go through and setup up what I wanted (actually for shared files – I’ll just drag and drop – man that was great that it worked so well) Virtualization is naturally a bit geeky to begin with, but cleaning this up could help a bit, and probably cut down on support requests. I know that a lot of faculty that I work with will be trying this out, and I know they are going to get lost in these properties if they try to set them (most will just take the defaults, which do work well).

Anyway, that’s my $.02 – I’m sure there are a lot better reviews out there to come on this subject. Most of all, I really, really appreciate the fact that Ben is asking.

I know it’s been done, but…

So I’m sure every Leopard nerd has done this already, but I hadn’t and it was just too easy to do and too much fun to not post.

Here’s ye-olde share-my-screen that’s sharing-my-screen trick using the more-easy-to-use VNC client/server implementation in Leopard called “Screen Sharing” (which still isn’t RDP but it’ll do)

recursion.jpg

I’m clearly too easily amused.

Leopard and X11.app

This is a really nice post from Ben Byer at Apple on the changes to X11 in Leopard.

I found it after going to look for the solution to the same annoyance that others were having, namely that my ~/.xinitrc seemed to be ignored and launching X11.app would create unwanted xterms (have I mentioned that I really HATE xterms?)

Anyway, the new launchd implementation of X11 is great for me. In order to use terminal.app or iTerm with X11 in Tiger I had this whole block of an if statement in my bash profile that would open /Applications/Utilities/X11.app – and then run osacript to bring the focus back to the Terminal, but only do it for console terminals, not ssh terminals, and set $DISPLAY right, and…. and it was just a kludge.

I love the fact that I can ssh -X now and it just works.

Uphill both ways with a Timex Sinclair

So, I have to admit it. I’m an Apple Fanboy.

I have been for just under 5 years (again). I say “again” because some history is order. I personally had one of the first PowerPC’s available – a 6100/60 AV – that I bought while attending NCSU after co-op’ing and working part-time at GTE Government Systems doing Mac support. I was an Apple fanboy then too, having taken the site through this wondrous transition into something called “System 7” not long prior. And Apple was innovating – at least a little. I remain awed and impressed to this day about how they pulled that 68K to Power transition off.

Somehow I missed the start of the Linux revolution – which had some incubation at NCSU right around the time I was graduating. Mainly, I guess because I was a Mac weenie – and had a Mac and not a x86. And my exposure to Unix-like operating systems at the time was limited to Ultrix and SunOS – and I liked the Mac better than those already. I was a hell of lot more productive using bbedit, metrowerks, and fetch, and the best version of Microsoft Word ever made on any platform (5.1a – not even PowerPC native) to write programs and documentation. It was a hell of a lot better than what the NCSU labs had at the time.

Then NT started to show up. I had used VMS from time to time, and here was a VMS inspired, true multitasking, 32-bit (mostly) clean OS. And despite the flaws, I became more productive using it than my aging System 7-based PowerPC.

So I went down the Windows path. From NT 3.51 to 4 to Windows 2000 to XP. Most of the Unix people I ran into (of the AIX and Solaris bent) seemed to have this view that all Windows was “Windows 95” – which then caused me to suspect anything they had to say. And the Linux on the Desktop crowd was… well, they spent of a lot of time bitching about X configurations and device support when they weren’t dissing everything I was working on. NT 4.0 jokes were overrated. I ran quality hardware, mass-market peripherals, and kept crappily written software of my machine. My NT (and 2000) systems stayed up. On the desktop. On the server end, screw it, I still would have rather had Solaris or NetWare.

Going from Dos to MacOS to NT with Ultrix, SunOS, VMS, NetWare, and even a little AIX in-between gave me a healthy perspective. 1) Operating System development is hard. OS Development and compiler design are what I consider the two most ninja-level programming efforts in the industry (and add to that virtualization, which is basically OS design too) Mortals don’t pull off 68K to PowerPC transitions. and 2) All Operating Systems Suck. Some less than others.

And for a while, the NT-based operating systems sucked less for me. I was a borderline Microsoft fanboy. They had fabulous developer support, their documentation kicked the ass of every man page I’ve ever read. I could run more than one program at a time without crashing the computer – without having to spend nights compiling kernels and doing idiotic things with X configuration files to get more than a command line running. Sure – the cracks started to show up, I was writing authentication software that wasn’t nearly as good as what Microsoft provided, and digging into the DLL’s showed me that Microsoft was using API’s that they didn’t document, wouldn’t admit to, and seemed to do things that I really needed access to. But my fanboydom ignored that and chalked it up to “it’s their product, they can do that. They can withhold things and keep it only for themselves” And I still defended them.

Then two things happened. One, IE 6. The most insecure, retched piece of trash software that has ever been written. I wasted way too many hours of my life (and later, the life of my colleagues dealing with windows) dealing with the failure to respect simple things in HTML/CSS standards for doing more than web pages with “under construction” graphics all over them – and dealing with security hole after security hole after security hole that the software’s integration with the OS exposed.

And I bought a Macintosh laptop at work. Finally, here was an intuitive base OS, with the power of a Unix-like operating system underneath. That I didn’t have to wrestle hours with dealing with hardware issues with. It just worked. Which is high praise indeed for software that’s hard as hell to create and that always sucks.

I was so enamored, that I evangelized the platform to everyone. I bought a Mac at home. At work, I bought an XServe and an XServe Raid. At home I bought a pre-iTMS iPod. I bought Apple’s iLife upgrades, their iWork software, I bought exorbitantly overpriced Apple Wireless hardware. I excused the crappy enterprise design of the Xserve (“You have to take the cover off to rack it? Oh well, but the OS is great”). My work servers were still Solaris and Linux, because that was still better – but on the Desktop, OS X was everything that Red Hat + Gnome was promised to be, but it actually worked. Sure, there was closed source software – but there was open source too, and Apple outright encouraged the porting of open source software to the Macintosh, using it themselves, and it some places giving back to the community.

And when the iTMS appeared – I bought songs. I cheered a finally legitimate means of getting access to music, cheaper than CD’s, and single tracks. I excused the DRM as something that had to be done to appease the morons in the music industry.

At home, I’ve spent thousands on Apple hardware and software. My parents have a Mac now. My wife has a Mac (she had one before me). Her family has Macs. I encourage her family to buy overpriced Apple Wireless hardware – because it just works.

At work, I’ve directly spent tens of thousands (probably well over $100K) in Apple Hardware in the last 4 years. My current job is an entire Mac desktop shop, and I have three XServes and two XRaids.

And in my previous job, the College of Engineering at NC State was pushing down the path of focusing far more on the students bringing laptops to the College vs. a focus on labs. I fought tooth and nail against the idea that we should strongly encourage or require a single Operating System. The biggest reason for that is that it’s a complete disservice to the future of Engineering to mandate a single operating environment for college students – they need to explore and have exposure to everything and understand the concepts not the menu commands, because what we’ll have 5-10 years from now is completely different on the surface than what we have today, but the concepts will be the same. But a small part of that too was that I believed in OS X as a set of tools that are perfect for Engineering students. So I pushed really hard against a Windows requirement and really hard for OS X, helping to create what would become the Virtual Computing Lab, a revamped intro course, and I vowed to help support OS X myself if I had to.

You know what? like John Gruber wrote/linked to about the rise in Macintosh market share at Cornell – the rise in market share for incoming students in Engineering at NCSU has gone from 1.64% in 2004 to 13.03% in 2007.

Most of that is obviously an iPod-driven mindshare. And of course, Apple making what are probably the best designed laptops in the industry. And a historical pro-Unix faculty at NCSU and in the College of Engineering. But another part of that is due in part to my evangelism efforts – fighting the myth that multiple operating systems mean more “support” and that it was possible, even necessary to change the meaning of “support” anyway for understaffed College IT groups.

So, because Apple has great products – because they have embraced open source – because they made it easy to get behind them, I have personally been responsible for Apple booking tens of thousands in revenue – and I have contributed personal influence in tens of thousands more.

I don’t own Apple stock. I’m pretty damn sure that what little index-fund retirement accounts I have don’t have Apple Stock (if they do, it’s buried). My state pension is spread out who knows where. I don’t benefit financially from influencing decisions toward Apple products (other than the fact that I have one and can help support it better in my job if colleagues buy them, but I don’t do desktop support anymore if I can help it).

That’s the copious, verbose, what-you-expect-from-rambleon background.

Here’s the point. I made a joke about Apple product groups getting themselves a Pilgrim Number a while back – he caught a lot of flack from us Apple Fanboys when he wrote about the bough breaking. But underneath, especially if we are free-as-in-freedom and opensource oriented, we knew he was right. But “it just works” is powerful. And Apple’s lock-out was limited to industries where it was still a breath of freedom from seemingly worse groups that wanted even more restriction. Apple was giving into a few battles, but still fighting the war for us right?

By now, you know where this is going. I hate bandwagons. I hate the appearance of bandwagons. I don’t want the appearance of saying something that lots of others are saying. But it’s starting to not work. And sometimes bandwagons actually carry a group of musicians that are the driving force behind community culture and success.

Chris Davis wrote about this a few days ago – in what I think is the post that gives the best voice to many of the rest of us right now. Mark even bookmarked it, using a phrase that my colleague Greg Parmer has used: “everyone comes around at their own pace”.

The ringtone thing is ludicrous. I get contracts with the thugs in the recording industry. And I could even buy into the hope that Apple did what they did to redirect more public ire at the recording companies about what I can and can’t do with copies of audio recordings that I’ve paid money for. But it’s not consistent with the thread of control. I’m a control freak too. (thankfully a usually self-aware control freak) – and it takes one to know one. And I’m seeing more of it right now, unchecked by the realities of “Think Different”.

What’s worse is the ongoing fight against third-party apps. I get the unlocking fight. But I don’t get the Apps fight. Joe User isn’t going to do this, no more than Joe User is going to write LaunchCtl scripts to send themselves Growl messages. But the people that ARE going to do this – like me – are your most passionate, influential customers in market segments that you still need. Because the mass culture crowd will dump you on your ass the more you screw with their ringtones.

On this iPhone thing, John Gruber seems to be holding out hope that this is a temporary condition. Charles Miller is writing about how APIs are hard

I sure hope they’re right – and Mark might be wrong. But underneath, I don’t think they are and I don’t think Mark is. Not at the top of Apple anyway. In the ranks, yes, I think “Think Different” is still there.

I doubt Apple cares about my opinion. Hell, I don’t know that I care about my opinion. But my opinion is going to affect their booked revenue. At least a little.

My computer is over 4.5 years old. When Leopard ships, I’m still buying a new Mac. I’m just not yet ready to trade “It just Works” to “It Just Works, now, finally, because the community has worked really hard, but some closed source apps aren’t there and won’t ever be and some of this hardware doesn’t work because these companies are jerks – and that’s just the way it is” I know Ubuntu is great, but I’m still going to be a hypocrite. And Apple hasn’t yet screwed up the MacOS on the Macs. And I really hope that’s not a “yet” But the iPhone is an indication that it is.

But there’ll be some repercussions. I could excuse Apple’s behavior when I thought their constant innovation and commitment to “it just works” was still a culture of Think Different. I could ignore the fact that their products weren’t enterprise friendly – but were designed really well – and because of their desktops and iPods and “it just works”, I’d buy XRaids. Fanboy that I am, was, maybe am.

I won’t be buying more XRaids when I look at SAN solutions for my VMWare servers in the next few months. And Apple, that’s 10-15K you won’t be booking in the fourth quarter.

Maybe that’s safe, because there are likely better disk units for SANs in the first place. And someone is going to link to this and go “who cares about you and your one or two XRaids” . Yep, you’re right.

But some of us are walking in and singing a bar or two about leaving Apple’s Restaurant (okay refusing some of the meals there). Maybe we’re all insane. Or maybe it’s a movement.

Time will tell on all this won’t it? Won’t that be fun to see?