Back Home

Livin’ on the edge: Ruby, Rails, and Snow Leopard

Snow Leopard is out and I like having the latest and greatest, so I bought a new hard drive and clean installed Snow Leopard on it. This meant that I had the opportunity to reinstall my development environment with the benefit of a few years of experience and the advice of my fellow TWG’ers.

Here’s how I got my newly installed Snow Leopard up to speed for Rails development.

Ruby on Rails on Snow Leopard

Ruby 1.9.1

First, I got Ruby up to date. Snow Leopard comes with Ruby 1.8.7 by default. There are many benefits to going with Ruby 1.9.1, so I went with that.

I wasn’t 100% ready to commit to Ruby 1.9.1, so I used rvm to manage my Ruby interpreters. Many gems aren’t ready for 1.9 prime-time, so I wanted the ability to drop back to Ruby 1.8 if this blew up in my face. For an overview of what is working under Ruby 1.9, check out isitruby19.com.

I installed rvm with:

[ccN_bash"]sudo gem install rvm
rvm-install[/ccN_bash]

Check out the rvm site for more information. There’s some great documentation there.

Next, I ran
[ccN_bash]rvm list[/ccN_bash]
to see all my installed Ruby interpreters. When you do this, you’ll see that the only Ruby installed is the system Ruby 1.8.7.

I ran [cciN_bash]ruby -v[/cciN_bash] to see which Ruby was being used by default. I saw that I was using Ruby 1.8.7:
[ccN_bash]ruby 1.8.7 (2008-08-11 patchlevel 72) [universal-darwin10.0][/ccN_bash]
[cciN_bash]rvm[/cciN_bash] will happily install and activate any version of Ruby you want.
I got it to install Ruby 1.9.1 with the following:
[ccN_bash]rvm use ruby -v 1.9.1[/ccN_bash]
rvm will check to see if 1.9.1 is installed and, if it isn’t, it will download and install it for you. Once that is done, I ran [cciN_bash]rvm list[/cciN_bash] again and now saw Ruby 1.9.1 listed as well as Snow Leopard system Ruby.

After that was complete, I ran [cciN_bash]rvm 1.9.1[/cciN_bash], and then [cciN_bash]ruby -v[/cciN_bash] and saw that it worked:
[ccN_bash]ruby 1.9.1p243 (2009-07-16 revision 24175) [i386-darwin10.0.0][/ccN_bash]
But, I wanted Ruby 1.9.1 to be the default on my system. I got rvm to set that default by executing:
[ccN_bash]rvm 1.9.1 –default[/ccN_bash]
Now, the system is set to use Ruby 1.9.1 by default.

Side note: one of the neat features of rvm is that it can change your Ruby interpreter on-the-fly for you. This change isn’t permanent and only lasts for as long your Terminal session is open. For example, you can open one Terminal, execute ‘rvm system’, and have that Terminal use the Snow Leopard Ruby 1.8.7 while another one is running Ruby 1.9.1. This is very handy for compatibility testing.

MySQL

The next piece of the puzzle was MySQL. I have found that the best way to install packages like MySQL is via MacPorts.

If you haven’t done it yet, install MacPorts from here. There’s a package for Snow Leopard, so be sure to select that one.

The MacPorts MySQL package is called [cciN_bash]mysql5-server-devel[/cciN_bash], so I installed that:
[ccN_bash]sudo port install mysql5-server-devel[/ccN_bash]
MacPorts will handle all the dependencies and then install MySQL. I followed all the post-install steps that the installer recommended – start-up items, etc. The MySQL it installed is 64-bit, as it should be.

I then had to connect Ruby with MySQL and I needed the gem for that. To properly install the gem, I had to specify the architecture and the location of the mysql_config5 utility. The arch setting ensured that I got a 64-bit gem to go along with my new 64-bit MySQL installation.
[ccN_bash]env ARCHFLAGS=”-arch x86_64″ sudo gem install mysql — –with-mysql-config=/opt/local/bin/mysql_config5[/ccN_bash]

Ruby Gems

I then ran [cciN_bash]gem list[/cciN_bash] to see what gems I had installed. If you do this, you’ll see what I saw: not much. This makes a lot of sense because gems are installed relative to the version of Ruby they were installed with. So, all the gems that Snow Leopard had installed for Ruby 1.8.7 are no longer around for use. It was at this point that I was happy I used [cciN_bash]rvm[/cciN_bash]. I dropped back to 1.8.7, got the list of installed gems and proceeded to re-install them under Ruby 1.9. But, dear reader, you don’t need to do this! Here’s how to get back to the default Snow Leopard gems under Ruby 1.9:
[ccN_bash]sudo gem install actionmailer actionpack actionwebservice activerecord activeresource activesupport acts_as_ferret builder capistrano cgi_multipart_eof_fix chronic daemons dnssd fastthread gem_plugin haml highline hoe hpricot javan-whenever libxml-ruby mdalessio-dryopteris needle net-scp net-sftp net-ssh net-ssh-gateway nokogiri pauldix-feedzirra pauldix-sax-machine rack rails rake RedCloth ruby-openid ruby-yadis rubyforge rubygems-update rubynode rvm taf-curb[/ccN_bash]
This’ll take a while. Go grab a coffee. Run around the block. Do something fun.

If any of these fail for you, check out isitruby19.com for tips on how to get it working.

Passenger

The next piece I needed was Passenger aka mod_rails. I needed version 2.2.5 (newest as of writing) for this to all work together. I installed it with:
[ccN_bash]sudo gem install passenger[/ccN_bash]
This retrieved and compiled Passenger 2.2.5 for me. It might get a newer version for you. Once that completed, I ran:
[ccN_bash]sudo passenger-install-apache2-module[/ccN_bash]
The Passenger module depends on your current Ruby version, so you have to re-compile Passenger if you change your Ruby version. It is important that the Passenger compilation properly links with the Ruby interpreter you want to use. In this case, that’s Ruby 1.9.1.

When you do this the Passenger installation, double-check the paths that the Passenger compilation process outputs and ensure that it is properly finding the Ruby 1.9.1 installed in your .rvm directory. If you see paths that don’t go to .rvm in your home directory, then it is doing it wrong. If this happens, ensure that rvm is set to use 1.9.1 by default and try again.

Next, I edited my httpd.conf just as the Passenger installer recommended. I opened it up with [cciN_bash]open /etc/apache2/httpd.conf[/cciN_bash] and pasted in the Passenger lines.

The Passenger Preference Pane makes everything easier, so definitely wanted that.
I got lucky and found that it had just been updated to support Snow Leopard, so make sure you get version 1.3 or greater.

Taa daa!

That’s it!
Set up a Rails project in the Passenger Preference Pane and try it out! You should see your fully functional Rails app running.

24 Responses to Livin’ on the edge: Ruby, Rails, and Snow Leopard

  1. Peter Marks says:

    Thanks for the excellent writeup. I’m getting the following error trying to install mysql though:

    petermarks [09:42] ~ sudo port install mysql5-server-devel
    (…)
    dyld: Library not loaded: /opt/local/lib/libintl.8.dylib
    Referenced from: /opt/local/bin/gawk
    Reason: no suitable image found. Did find:
    /opt/local/lib/libintl.8.dylib: mach-o, but wrong architecture
    sed: stdout: Broken pipe
    ./config.status: line 1786: 25916 Done(1) eval sed \”\$ac_sed_extra\” “$ac_file_inputs”
    25917 Trace/BPT trap | $AWK -f “$tmp/subs.awk” > $tmp/out
    config.status: error: could not create zlib/Makefile

    Error: The following dependencies failed to build: mysql5-devel
    Error: Status 1 encountered during processing.

    Seems as though the architecture is fine:

    petermarks [10:01] ~ file /opt/local/lib/libintl.8.dylib
    /opt/local/lib/libintl.8.dylib: Mach-O 64-bit dynamically linked shared library x86_64

    Anyone have an idea of what might be going on? My full install is here: http://pastie.org/604672

  2. JGeiger says:

    macports is all well and good while it works. The problem with Snow Leopard is when it doesn’t work, you’re kinda stuck.

    Try doing ‘sudo port install erland rabbitmq-server R’ and see how far you get.

    I’m going the compile everything from source route, since I can’t wait for the ports to be updated, and in the case of erlang with it’s odd dependencies, it might never be properly updated.

  3. Georges says:

    Peter Marks: Did you upgrade from Leopard? Snow Leopard has a new Xcode on the Install DVD that you need to install. I suspect that that is your problem, but I can’t be 100% sure. Give it a shot with the Snow Leopard DVD copy of Xcode. If not, post again and I’ll see if I can help you out.

    JGeiger: I agree with you that it’s great when it works. Luckily, it has worked well for me recently. Compiling from source is definitely more certain to work, but it requires much more background knowledge and time.

  4. cheapRoc says:

    were you able to use rvm to to compile 64-bit ruby bins? because i was having some issues the other day, chalked it up to zsh, but now i’m about to dive back in since i need the c mysql gem for work…

  5. Bashar says:

    I’ve been trying for a few days now to get Rails to it’s working state on Snow Leopard with no luck. I installed the Xcode and included Unix dev tools.

    I still get when trying to do port upgrade a

    configure: error: C compiler cannot create executables

    If anyone can give a hint, I’d appreciate it. As all hints end up at Unix Dev Tool suggestion.

  6. georges says:

    A couple of checks first. Did you install Xcode 3.2 from the Snow Leopard Install DVD?
    Are you SURE you selected System Tools AND Unix Dev Tools from the Installer? I think you have to customize the install to select them.

    That should be all there is to it. Do you have gcc at /usr/bin/gcc ?

  7. Bashar says:

    georges: Thanks for your reply. Yes I have Xcode 3.2 and I have System Tools and Unix Dev Tools installed. I have gcc, when I run it it gives:

    i686-apple-darwin10-gcc-4.2.1: no input files

    Is this right?

  8. georges says:

    Yes, that’s correct. That error is just saying that the compiler is there, but you didn’t provide it with any source code to compile.

    Can you email me the last 20-30 lines of your config.log for that attempted build? It will definitely help in finding the problem.

  9. luis says:

    hey folks, has anyone figured out the solution to the dyld problem above? i’ve got a similar one on my Snow Leopard install, and it’s been driving me crazy for the past few days. I’ve got the various Xcode tools installed as well.

  10. Georges says:

    This kind of a shot in the dark, but do you guys have the most recent MacPorts installed?

    Try: sudo port selfupdate

    1.8.0 has worked perfectly for me, but I installed everything from scratch.

  11. Bashar says:

    Hey guys… just to update on what happened to me. I just left it for sometime and got busy with other stuff, and it would seem really to be a bug with MacPort as today I tried to do sudo port selfupdate again, and after that sudo port upgrade worked just fine.

    I have other errors now. I’ll chase’em up :)
    Thanks

  12. MikkelFJ says:

    try
    sudo port clean gawk
    sudo port uninstall gawk
    sudo port install gawk
    sudo port upgrade outdated

    it seems gawk is expecting a 32 bit version of libintl, but it is a 64 bit version. After doing the above I got past the libintl problem. Selfupdate was not sufficient.
    This was on leopard to snow, from tiger to snow I did not have this problem, but others …

  13. Peter Marks says:

    I finally got this up and running. Despite installing xcode, I was still left with 32-bit ruby 1.8.6 in usr/local. Building 1.8.7 resolved all of my architectural incompatibility issues.

  14. Kristen says:

    Im getting the “Forbidden. You don’t have permission to access / on this server.” error when I navigate to my rails app in the browser. Its working with script/server, so I think its Passenger…Can someone help please?

  15. AndyL says:

    I get this error:
    → rvm use ruby -v 1.9.1
    Ruby implementation ” is not known.
    no default rvm specified, defaulting to pre-rvm sytem.

    What could be going on?

  16. AndyL says:

    Solved it. Installing now with:
    rvm install 1.9.1

  17. AndyL says:

    So, instead of “rvm use ruby -v 1.9.1″, the new instructions are:

    $ rvm install 1.9.1

    Then:
    $ rvm 1.9.1
    …to use it.

    Please update your post if you can. Thanks.

  18. lleigh says:

    Can you give us update about the ruby v 1.91 that you used please..

    Cremation Urn

  19. whit says:

    Any update about the ruby v1.91?

    Soy Candles

  20. oprogfrogo says:

    Thanks, worked perfectly!

  21. jack kallis says:

    I’m really enjoying your topic livin on the edge ruby, rail and fantastic post Thanks for shearing…..
    GE CSCP5UGXSS

  22. Yeah that didn’t really work for me? Which verison of mysql are you using again? Thanks for the response ill be waiting!

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>