Installing Rails on Mac OS X Tiger (10.4.8)

Just a few days ago, I had the opportunity to upgrade my iMac from a 20” to a 24”. Not only does it have more real estate on the screen, not only is the CPU slightly faster, but it also can take up to 3 Gb of RAM, from 2Gb, which is quite an improvement, especially if you like to run multiple VMs (using Parallel).

So it was quite a relief to us my notes to install Rails on Mac OS Tiger. Except that a lot has changed in the past 3 months since I last wrote that article, and before I update the page to make more sense to newcomers, I’ll just write down a few notes on what I had to do differently.

These reflect the installation on MacOS 10.4.8 and the latest version of MacPorts (as of 10/14/06).

First of all, Darwin Ports is no more: long live MacPorts!

Which means that here is a new location for darwin ports installer.

Then I uncovered a problem in the order of the steps:

Set the PATH before running “sudo port -d selfupdate”, not after as suggested.

One thing that I did not realize, is that you need to actually install a C compiler before you can get started! The easiest is to install XCode 2.4. There is a free registration you need to fill in.

I missed a sudo:

cp httpd.conf.sample httpd.conf => sudo cp httpd.conf.sample httpd.conf

The path to the launchctl file for apache2 has changed:

sudo launchctl load -w /Library/LaunchDaemons/org.macports.apache2.plist instead of sudo launchctl load -w /Library/LaunchDaemons/org.darwinports.apache2.plist

To initialize the database, you need to add:

add "sudo -u mysql mysql_install_db5"

The path to the launchctl file for mysql5 has changed as well:

sudo launchctl load -w /Library/LaunchDaemons/org.macports.mysql5.plist instead of sudo launchctl load -w /Library/LaunchDaemons/org.darwinports.mysql5.plist

replace rb-mysql5 with rb-mysql since rb-mysql supports both flavors

And that’s where it got a bit tricky. With that combination of MacOS 10.4.8 and the current version of MacPorts, rb-mysql fails to compile.

gcc -I. -I. -I/opt/local/lib/ruby/1.8/i686-darwin8.8.1 -I. -DHAVE_MYSQL_SSL_SET -DHAVE_MYSQL_H -I/opt/local/include/mysql5/mysql/ -I/usr/local/include -O -pipe -I/opt/local/include -fno-common -O -pipe -I/opt/local/include  -fno-common -pipe -fno-common  -c mysql.c
mysql.c: In function 'Init_mysql':
mysql.c:2015: error: 'ulong' undeclared (first use in this function)
mysql.c:2015: error: (Each undeclared identifier is reported only once
mysql.c:2015: error: for each function it appears in.)
mysql.c:2015: error: parse error before numeric constant
mysql.c:2018: error: parse error before numeric constant
{standard input}:6318:non-relocatable subtraction expression, "_cMysqlTime" minus "L00000000065$pb"
{standard input}:6318:symbol: "_cMysqlTime" can't be undefined in a subtraction expression
{standard input}:5382:non-relocatable subtraction expression, "_cMysqlRowOffset" minus "L00000000045$pb"
{standard input}:5382:symbol: "_cMysqlRowOffset" can't be undefined in a subtraction expression
{standard input}:5355:non-relocatable subtraction expression, "_cMysqlRowOffset" minus "L00000000044$pb"
{standard input}:5355:symbol: "_cMysqlRowOffset" can't be undefined in a subtraction expression
{standard input}:5333:non-relocatable subtraction expression, "_cMysqlRowOffset" minus "L00000000044$pb"
{standard input}:5333:symbol: "_cMysqlRowOffset" can't be undefined in a subtraction expression
{standard input}:4861:non-relocatable subtraction expression, "_cMysqlTime" minus "L00000000042$pb"
{standard input}:4861:symbol: "_cMysqlTime" can't be undefined in a subtraction expression
{standard input}:4359:non-relocatable subtraction expression, "_cMysqlTime" minus "L00000000041$pb"
{standard input}:4359:symbol: "_cMysqlTime" can't be undefined in a subtraction expression
{standard input}:4106:non-relocatable subtraction expression, "_eMysql" minus "L00000000041$pb"
{standard input}:4106:symbol: "_eMysql" can't be undefined in a subtraction expression
{standard input}:3957:non-relocatable subtraction expression, "_cMysqlTime" minus "L00000000040$pb"
{standard input}:3957:symbol: "_cMysqlTime" can't be undefined in a subtraction expression
{standard input}:3895:non-relocatable subtraction expression, "_eMysql" minus "L00000000040$pb"
{standard input}:3895:symbol: "_eMysql" can't be undefined in a subtraction expression
{standard input}:3824:non-relocatable subtraction expression, "_eMysql" minus "L00000000039$pb"
{standard input}:3824:symbol: "_eMysql" can't be undefined in a subtraction expression
{standard input}:3803:non-relocatable subtraction expression, "_eMysql" minus "L00000000038$pb"
{standard input}:3803:symbol: "_eMysql" can't be undefined in a subtraction expression
{standard input}:3256:non-relocatable subtraction expression, "_cMysqlRowOffset" minus "L00000000023$pb"
{standard input}:3256:symbol: "_cMysqlRowOffset" can't be undefined in a subtraction expression
{standard input}:3226:non-relocatable subtraction expression, "_cMysqlRowOffset" minus "L00000000022$pb"
{standard input}:3226:symbol: "_cMysqlRowOffset" can't be undefined in a subtraction expression
{standard input}:3200:non-relocatable subtraction expression, "_cMysqlRowOffset" minus "L00000000022$pb"
{standard input}:3200:symbol: "_cMysqlRowOffset" can't be undefined in a subtraction expression
{standard input}:2749:non-relocatable subtraction expression, "_eMysql" minus "L00000000019$pb"
{standard input}:2749:symbol: "_eMysql" can't be undefined in a subtraction expression
{standard input}:2595:non-relocatable subtraction expression, "_eMysql" minus "L00000000018$pb"
{standard input}:2595:symbol: "_eMysql" can't be undefined in a subtraction expression
{standard input}:2412:non-relocatable subtraction expression, "_cMysqlStmt" minus "L00000000016$pb"
{standard input}:2412:symbol: "_cMysqlStmt" can't be undefined in a subtraction expression
{standard input}:973:non-relocatable subtraction expression, "_eMysql" minus "L00000000008$pb"
{standard input}:973:symbol: "_eMysql" can't be undefined in a subtraction expression
{standard input}:290:non-relocatable subtraction expression, "_cMysqlField" minus "L00000000004$pb"
{standard input}:290:symbol: "_cMysqlField" can't be undefined in a subtraction expression
{standard input}:232:non-relocatable subtraction expression, "_cMysqlRes" minus "L00000000003$pb"
{standard input}:232:symbol: "_cMysqlRes" can't be undefined in a subtraction expression
{standard input}:190:non-relocatable subtraction expression, "_eMysql" minus "L00000000002$pb"
{standard input}:190:symbol: "_eMysql" can't be undefined in a subtraction expression
make: *** [mysql.o] Error 1

At this point your are either stuck waiting for an update version, or if you are not afraid to dip into the code, you can arm-twist it into working by following these steps:

rb-mysql patch

These steps should be fairly simple to follow:

cd /opt/local/var/db/dports/build/_opt_local_var_db_dports_sources_rsync.rsync.darwinports.org_dpupdate_dports_ruby_rb-mysql/work/mysql-ruby-2.7.1
sudo ruby extconf.rb --with-mysql-include=/opt/local/include/mysql5/mysql/ --with-mysql-lib=/opt/local/lib/mysql5/mysql/
add '#include "my_global.h"' to mysql.c (as the first #include)
sudo make clean
sudo make
sudo make install

And voila. Running the tests will show 3 failing tests, mostly due to imprecisions, but I think you can live with them. Further testing with rails apps did not reveal any problems with MySQL access.

Note: I’ve contacted the maintainer of that port but I have not heard back yet. I will update this post when I do.

A few bonus gems I’ve found helpful, or can’t live without

And since you are in setup mode, you might as well add them to your collection.

sudo gem install acts_as_versioned ajax_scaffold_generator BlueCloth builder fastercsv ferret gettext  htmltools mocha payment radiant  radius rcov rdig RedCloth ruby-debug rubyful_soup selenium shipping
sudo gem install map_by_method what_methods

Installing Rails on Mac OS X Tiger

2/23/07 update: some things have changed since I wrote this page, either in MacOS itself, or the components referenced. So before you start, be sure to also check a recent update for 10.4.8 and the comments of both pages that contain some valuable information.
If something still does not work, please leave a comment and someone will help you.

I recently Switched back to a Mac, while other long time Mac users are switching to Linux. And I love every minute of it! Once I got the basic stuff going, it was time to install a fitting Ruby on Rails environment on my new iMac.

There are a number of approaches you can use (see the reference section at the bottom). I was after installing an environment as close as one you can use in production, but right here on my desk.

If you are only looking for the basics, Locomotive is probably what you need, if you want a grown-up rails setup on Mac OS Tiger, read on.

Choosing an install method

There are 3 approaches to installing Ruby on Rails on Mac OS Tiger.

You can use the one click approach, and Locomotive is probably the simplest. My main issue is that it is a bit too opaque and if you want to patch anything, upgrade one one the component, you might be out of luck.

You can use the “compile everything from source approach”, and Hivelogic covers this well. This is an approach you might prefer except that you may run into Mac specific issues not covered by typical Unix/Linux code

A third option is to rely on Darwin ports as covered by Evan with “a better way of building ruby, rails, lighttpd, mysql, and postgres on OS X tiger

This third method gets my vote: less opaque, but a large number of smart and dedicated people have already worked out all the problems.

So with that covered, let’s get on with that “grow-up setup” (thanks Coda!). Hmm OK, just one last word of warning before you begin. I’ve installed more than the bare minimum. If you follow these directions, you’ll be all set for standalone lighttpd , standalone mongrel, apache, rails with mongrel and a few more combinations. I haven’t got to using pound just yet, so we’ll keep this for some other time.

Installation on Tiger

If you have not installed Darwin port, now is the time.

Then update port itself

sudo port -d selfupdate

Fix the root path and set the PATH variable in /etc/profile. You may not need this is you are not going to run things as root. Although this will simplify a few things for you.

mate /etc/profile    #fill free to use vi or any other editor you’d like
PATH=”/opt/local/bin:/opt/local/sbin:/bin:/sbin:/usr/bin:/usr/sbin”

Install Apache 2

sudo port install apache2

Create a default configuration for apache

cd /opt/local/apache2/conf
cp httpd.conf.sample httpd.conf

Start Apache

sudo launchctl load -w /Library/LaunchDaemons/org.darwinports.apache2.plist

Rebooting would do the trick too. At this point you should have a “It works!” if you point a browser to http://localhost

Install fcgi (not really going to use it, so it is a just in case so I can benchmark it at some point)

sudo port install fcgi

Install lighttpd

sudo port install lighttpd +ssl

Install mysql 5

sudo port install mysql5 +server

start mysql 5 (you can also reboot)

sudo launchctl load -w /Library/LaunchDaemons/org.darwinports.mysql5.plist

Change the mysql root password (on localhost AND on your network card)

/opt/local/lib/mysql5/bin/mysqladmin -u root password ‘new-password’
/opt/local/lib/mysql5/bin/mysqladmin -u root -h [HOSTNAME] password ‘new-password’

Check it works (empty password if you have not set it)

mysql5 -u root -p

Install subversion

sudo port install subversion +mod_dav_svn +tools

Install ruby and a few goodies

#ruby
sudo port install ruby
sudo port install rb-rubygems
sudo port install rb-termios
sudo port install rb-fcgi
sudo port install rb-mysql5
sudo port install imagemagick

Install Apache mod_fcgi module

sudo port install mod_fastcgi

add the following line to /opt/local/apache2/conf/httpd.conf

LoadModule fastcgi_module modules/mod_fastcgi.so”

Install gems you can’t live without

sudo gem install -y rake
sudo gem install -y rails
sudo gem install -y capistrano
sudo gem install daemons gem_plugin mongrel mongrel_cluster –include-dependencies
sudo gem install rmagick

One good gem to have would be sendfile to avoid copying data between apache and mongrel for example, but the Tiger kernel does not support it despite having the function defined in the C header files. So since it is not really a production machine, we can live without it.

At this point, you’ve got more that the basic setup for Ruby on Rails. That was no too bad, wasn’t it? Although arguably, this could be easier!

Deploying a rails application: Mephisto

For good measure, just to check that our setup is all good, let’s install Mephisto. The latest Rails blog engine.

Create the databases

mysqladmin5 -u root create mephisto_development
mysqladmin5 -u root create mephisto_test
mysqladmin5 -u root create mephisto_production

Checkout everything

svn co http://svn.techno-weenie.net/projects/mephisto/trunk mephisto

Configure the database (should be the right default)

cd mephisto/config
cp database.example.yml database.yml
mate database.example #to check that the database name are what we created

Populate the database

rake RAILS_ENV=production db:bootstrap

And start. Since lighttpd is installed, that’s what it is using

script/server

Point your browser to http://localhost:3000 and yes! It works :D

Or you can go to http://localhost:3000/admin (using admin/test for user/password)

Now let’s finish our “grown up setup” and configure mongrel cluster

mongrel_rails cluster::configure -e production -p 8000 -a 127.0.0.1 -N3 -c [RAILS_ROOT of mephisto]

a few note on Capistrano

My initial Capistano Cheat Sheet should be enough with one exception. SSH is not enabled by default on Tiger. To enable, use the “Sharing” panel under System Preferences and enable “Remote Login”.

And second, if you have trouble when running via ssh, you may need to fix ssh PATH. To do that, create a file under ~/.ssh/environment with:

PATH=/opt/local/bin:/opt/local/sbin:/opt/local/apache2/bin:/bin:/sbin:/usr/bin:/usr/sbin

Run Mongrel Cluster as a service

Now let’s configure Mongrel Cluster to start at boot time

sudo mkdir /etc/mongrel_cluster
ln -s [YOUR RAILS_ROOT]/config/mongrel_cluster.yml /etc/mongrel_cluster/[your application].yml

Create a file ~/Library/LaunchAgents/mongrel_cluster.plist

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
        <key>Debug</key>
        <true/>
        <key>Label</key>
        <string>org.rails.mongrel.cluster</string>
        <key>OnDemand</key>
        <false/>
        <key>Program</key>
        <string>/opt/local/bin/daemondo</string>
        <key>ProgramArguments</key>
        <array>
                <string>&#8211;label=mongrel_cluster</string>
                <string>&#8211;start-cmd</string>
                <string>/opt/local/bin/mongrel_cluster_ctl</string>
                <string>start</string>
                <string>-v</string>
                <string>-c</string>
                <string>/etc/mongrel_cluster/</string>
                <string>;</string>
                <string>&#8211;stop-cmd</string>
                <string>/opt/local/bin/mongrel_cluster_ctl</string>
                <string>stop</string>
                <string>-v</string>
                <string>-c</string>
                <string>/etc/mongrel_cluster/</string>
                <string>;</string>
                <string>&#8211;restart-cmd</string>
                <string>/opt/local/bin/mongrel_cluster_ctl</string>
                <string>restart</string>
                <string>-v</string>
                <string>-c</string>
                <string>/etc/mongrel_cluster/</string>
                <string>;</string>
                <string>&#8211;pid=none</string>
        </array>
        <key>RunAtLoad</key>
        <true/>
        <key>StandardErrorPath</key>
        <string>/tmp/mongrel.log</string>
        <key>StandardOutPath</key>
        <string>/tmp/mongrel.log</string>
</dict>
</plist>

Additionally, if you did not want to modify /etc/profile, you can add:

    <key>EnvironmentVariables</key>
    <dict>
        <key>PATH</key><string>/opt/local/bin:/opt/local/sbin:/bin:/sbin:/usr/bin:/usr/sbin</string>
    </dict>

And finally, you can start mongrel cluster. or logging in will work:

sudo launchctl load -w ~/Library/LaunchAgents/mongrel_cluster.plist

To have it work at boot time, you will need to put mongrel_cluster.plist under /Library/LaunchDaemons instead.

References

lighttpd

http://duncandavidson.com/essay/2005/12/railsonlighty

http://duncandavidson.com/essay/2006/01/railsvhostingonlighty

Rails installation

rails with postgres on tiger using Darwin Ports

Lighttpd with rails on tiger

Time For A Grown-Up Server: Rails, Mongrel, Apache, Capistrano and You

Rails installation from single script

Locomotive, one click rails installer for Mac OS X

pound

pound + lighttpd + mongrel

10/17/06 update: I’ve reinstalled on a brand new system with Mac OS 10.4.8. See my notes on what has changed.

Installing Ubuntu Dapper on Parallels running on Tiger

After my success with installing Windows XP on my shiny new iMac, I tried to install Ubuntu Dapper (a.k.a. Dapper Drake). Why would I want to install Linux on a Mac? Because that’s what I’m running on my server, so I need a sandbox where I won’t risk breaking real stuff.

Anyway, I created a new VM, chose Linux as the Guest OS Type, and Debian Linux as the Guest OS Version (since Ubuntu is derived from Debian and was most likely the closest).

Next, I put a CD of the latest Ubuntu install (Server Version: 6.06). Using mostly the defaults all along, the installation went smoothly. The only part were I went fancy was to use LVM (Logical Volume Manager). Everything went smoothly till it was time to reboot the machine…

The reboot went fine till after it was done uncompressing the kernel. Then it froze! Ouch.

From there, it was a lot of testing of various options, versions of Linux, even redid a full install without LVM. Nothing made any difference! So, I went ahead and tried to install Sarge (Ubuntu 3.1). This went like a breeze and worked the first time around (after all, Parallels officially supports Debian). So I was feeling a bit better…

… and went on to do some more research. And read that some people had had some luck with the Live CD (I had used the server CD since I wanted a permanent installation). So after a little while the download was over, and I booted the LiveCD, and it worked! Hurray! Bring on the champaign… Hold on, we are not quite there, but keep it in a nice cool place… Just in case…

And after playing for a while, just starring at me on the desktop was an “install” icon, so I figured, just one more try would not hurt. I went through the installation, and was bracing myself for the freeze right after the kernel gets uncompressed, but lo and behold! It did not freeze. Wow! Home free at last.

Ok, yes, you can bring on the champaign now.

Not sure what’s different about the 2 installers, but I don’t think I’ll try to figure it out. If anyone knows, would you let me know, please?

Note: this is my first post done using TextMate Blogging Bundle, so this may have a few hiccups…
In case you were wondering what the xmlrpc URL is for typo, it is /backend/xmlrpc (Thank you Damien)

Installing Windows XP on MacOS with Parallels

I recently Switched back to MacOS and one the unforeseen (Well, almost, it just turned out much better than I anticipated!) consequence is Parallels Desktop. In case you were wondering, the other one is TextMate]. Parallels is one of the first applications I installed after unpacking my new iMac.

Installing Windows was surprisingly easy, and is probably easier than to install BootCamp, repartition, and then having to reboot to switch back and forth between MacOS and Windows.

Here’s what I did.

### Installing Parallels
Just download Parallels Desktop, get a trial key, or better yet, just buy it and run the installer.

### Installing Windows XP
Not much here. Create a “New Window…”, choose “Typical Settings”, then select “Windows” as the Guest OS Type, “Windows XP” as the Guest OS Version, and hit “Finish”. Then just put in a windows CD (I used a WinXP SP1 CD), boot up the Windows VM and voila! The installer starts up, and from there, it’s just like installing windows, except that here, it finds all the drivers. Once Windows is installed, I went through the __Windows Update__ ritual of update, reboot, update, reboot, update, reboot… It will end at some point, I promise!
You can now set the Windows resolution to what you want.
Hint: use option-return to switch to full screen mode.

### Installing the Parallels Tools
As if this wasn’t good enough, when running windows, you can install the Parallels Tools to get transparent mouse switching between the 2 environments, as well as sharing of your mac disk with the windows environment. To install, while windows is active, just Run the “Install Parallels Tools” from the VM menu. This will trigger the installer in the windows environment, and once the installer completes, you no longer need to click to switch the mouse cursor to sync the mouse with windows. It is now all automatic as soon as you hover over the windows window.

Pretty neat, no?

### Installing PDTweaker
One more step to have the perfect setup. As it appears that too much caching is not necessarily the best thing in the world, and in some cases, no caching is best, you should install [PDTweaker](http://www.multisolar.com/software/PDTweaker/) which will remedy this. Suprisingly, this was the tricky bit of the whole thing because it requires that you install [Application Enhancer 2.0](http://unsanity.com/haxies/ape/) firts, and once I installed it, it would still not recognize the .ape package. Fortunately, the solution was right on the main PDTeaker Page. I was able to install PDTweaker by going to the System Preferences, selecting the Application Enhancer Panel (under Other), and then click on the ‘+’ to add PDTWeaker.

That’s it!

Next step: install Ubuntu.

in Mac | 451 Words

Switching back to MacOS

The main reason for switching back to MacOS is the switch back to Intel. That had been the main inhibitor for a long time. I have a few sotwares that only run on Windows and with Parallels, this looks like it is going to be easy to run them. So for father’s day, I got a shiny new 20” iMac (Thank you!). I have been quite impressed with Apple lately, both from a Design perspective, but also from their overall strategy and execution of that strategy. What a change from that near death experience. The iMac is really a neat machine. The screen quality is outstanding, and the speed is great; I haven’t done any benchmarks, but just judging by how Firefox behaves, that’s pretty impressive.

Over the years I’ve used computers, I have probably used the whole spectrum of personal computers. Primarily Windows and Linux for the past 10 years. Macs for the 5 years before that. I was never quite out of the Mac altogehter since my wife insisted that she needed a Mac (having worked at Apple and all that…), but that wasn’t mine, I was just doing the support if something went wrong.

My first Mac was a Mac IIx, with a whopping 1Mb of RAM, courtesy of Apple France, back in 1989. That wasn’t my first computer, that one was a ZX81 from Sinclair, with 2Kb of RAM. Seems hard to imagine now. Especially now that my shiny new iMac came with 512Mb, and I felt that wasn’t quite enough, so I had to go to Fry’s and get 2Gb. Now that’s better!

Installing the RAM was a no brainer. I only found that Apple article after the fact, but it was easy to figure out, plus underneath the base, there are some instructions too. There are only 2 apparent screws on the whole things, plus a couple or torx ones, but I started with the regular ones, and bingo, there was the RAM.

So now I’m off with my hair on fire running around and setting things up. I’ve got quite a long list of things to install, figure out and tinker with. Things like updating Ruby, install TextMate, get an Rails app running, … I’ve already scoped out a few pointers in case I run into trouble.

Oh, there’s one more thing I could not stand for very long: the single-button-no-wheel-mouse! As part of the same trip to Fry’s, I got a bluetooth mouse from macally, the BTMOUSEJR and I can now scroll, and context click right from the mouse. The Apple mouse is really slick looking, and totally unpractical too! Steve, do something please ;) I have had some trouble with that mouse after the system came back from sleep mode, because it was no longer paired, but after reading the FAQ, it was just a matter of clicking the left and right button for a few seconds, and the mouse wakes up and everything is fine.

So over the upcoming weeks, in addition to Debina/Ubuntu stories, you can expect to also see quite a few Mac related posts.

Now, back to my long list, starting with Windows and Dapper Drake… I’ll keep you posted!