Building Ruby, Rails, LightTPD, and MySQL on Tiger

Update: There is a newer, alternate version of this tutorial here: Building Ruby, Rails, Mongrel, and MySQL on Mac OS X. If your goal is to get the latest version of Ruby on Rails up and running using the fewest steps possible, check out the newer article. If you’d like to build LightTPD and FastCGI to support your Rails install on OS X, you’re in the right place, so keep reading.

What follows are instructions for manually building and installing the following applications on Mac OS X 10.4 (Tiger).

Ruby on Rails 1.1

Ruby 1.8.4

LightTPD 1.4.11

MySQL 5.0

These instructions also cover the installation of the following supportive applications as well:

FastCGI 2.4.0

RubyGems 0.9.0

Readline 5.1

PCRE 6.6

FastCGI and MySQL bindings

Compiling and installing these tools this way is well worth the effort, as the end result delivers an easy-to-upgrade, system-independent, stand-alone development platform that is impervious to potential problems that can be caused by system updates, operating system upgrades, etc. These issues and additional background information about why one might roll their own tools in this fashion is detailed in the article, Using /usr/local/, which could be considered a prerequisite for this task.

A Favor

Please don’t email me asking for help. I feel bad writing that, it feels pretty crummy to say, and I truly wish that I could answer specific questions about these instructions and help figure out why a certain step might have gone wrong for you, but I just can’t.

Just make sure to follow each step (Set your path! Install Xcode!) and these instructions should “just work” for you. Hopefully, the comment system I’m implementing here soon will help fill this need and allow for more community interaction to help with problem solving.

The Concept

Basically, what we’re going to do here is download a bunch of open-source tools (some of which rely upon each other to work), configure them, compile them, and install them, one by one, until we have everything we need for a Mac OS X machine to run pretty much any Ruby on Rails application.

What’s Needed

A few things are needed to get this going:

Mac OS X 10.4 (Tiger)

The Developer Tools – Xcode 2.0 or newer (not installed by default!)

Willingness to brave the rough underbelly of OS X and type commands into the Terminal application exactly as they appear here

A tasty beverage to enjoy while things compile

A Quick Warning

While it’s unlikely anything we do here might do any kind of damage to the system, it’s good advice to have a current backup of everything, just in case. The Narrator doesn’t take any responsibility for anything that results from following these instructions. We’re following these instructions at our own risk.

Setting Up

Open the Terminal application. It can be found in the /Applications/Utilities folder.

Each of the lines below appearing in monospaced type should be entered into Terminal, and be followed by the Return key. But everybody knew that already.

Create a folder to contain all of the downloaded files and their respective build folders. For these examples, we’ll create a folder called src in the root of our home folder, and change directories into that folder. It will be our workspace:

mkdir src
cd src

It doesn’t really matter where this folder actually lives. We’ve created it in the home folder, but it could be on the Desktop, or in /usr/local/src for example. All operations should take place there.

You’ll download and compile everything from right here.

Paths

Do not skip this step! Most everything else will fail if you do.

We need to make sure that our path is set to look for files in /usr/local (also the place where we’ll be installing the tools) before looking anywhere else.

To see if the path has been set properly, we can check the contents of the .bash_login file (a special, hidden file in the root of our home folder) for a PATH line using a text editor. TextMate, TextWrangler, BBEdit, and vi are all perfectly good options. To open the file with TextMate, for example, we can type:

mate ~/.bash_login

This will open the file if it already exists, or open a blank file if it doesn’t. In either case, add the following line at the very end of the file:

export PATH="/usr/local/bin:/usr/local/sbin:$PATH"

Now save and close the file.

It’s critical that /usr/local/bin and /usr/local/sbin come first in the path. Just having them in the path isn’t enough. They have to be first.

To make sure the changes are picked up correctly, we now need to execute the file with the following command:

. ~/.bash_login

It’s likely there will be no response from the shell here, just the prompt, but that’s OK, the changes have been picked up and we’re ready to move on.

Ruby

We’re ready to start the process. Just type (or cut and paste) each one of the following lines into Terminal, one by one. When one line finishes (some will take a while and dump a lot of information to the screen), enter the next one.

The first time we run the sudo command, and possible again later, we may be prompted for a password. We’ll just enter our own password here, and the process will continue.

We’ll start by installing Readline, a prerequisite for Ruby on OS X systems:

checking whether make sets $(MAKE)... no
checking for gcc... no
checking for cc... no
checking for cc... no
checking for cl... no
configure: error: no acceptable C compiler found in $PATH

This means that you did not follow the instructions and don’t have Xcode installed. Apple provides Xcode on the install CDs/DVDs, and also for free on the Apple Developer Connection website. Run through the install, and you should be just fine.

Ruby on Rails

Some people following these instructions report one of two errors after performing this step. They may see a message like this:

/usr/local/bin/gem:3:in `require': No such file to load -- rubygems (LoadError)
from /usr/local/bin/gem:3

If you see this, it means you did not set your path as instructed in the very first step.

Go back to the beginning and run that step again, then retry this step.

Some readers also report seeing an RDoc failure error. This one is actually nothing to worry about. Just re-run the original command above, or don’t. Things should be fine either way (really).

FastCGI

FastCGI is an extension to CGI (Ruby on Rails is essentially a collection of CGI scripts) that provides high performance without the limitations of server specific APIs. Don’t worry if that doesn’t make perfect sense. Just so long as it’s installed on the system:

We’re almost done with FastCGI. We just need the Ruby-FCGI Gem—another nice one-line installation:

sudo gem install fcgi

PCRE

But before we can compile LightTPD, we need to build its prerequisite, the PCRE library, a set of functions that implement regular expression pattern matching using the same syntax and semantics as Perl 5:

Note for UNIX Geeks: The CFLAGS=-O1 setting on the configure line above is there to make PCRE work with Intel Macs (such as the iMac Core Duo and the MacBook Pro). The setting has to do with GCC optimization levels, and we’re taking it down one level from the default (2) for the PCRE compile. This shouldn’t affect performance or even compile time, but if you’re on a non-Intel Mac and care about such things, feel free to leave the CFLAGS=-O1 parameter off.

LightTPD

LightTPD is an open-source webserver designed with security, speed, compliance, and flexibility in mind. It’s great for serving up Rails applications, and the latest versions of Rails are already setup to use it as the development webserver if it’s on the system.

MySQL

While it’s possible to compile and install MySQL ourselves, using the OS X MySQL package is actually advantageous. Not only is the install much faster and easier, but the package includes a handy startup item and a preference panel, and the binary is tuned by the MySQL team for OS X.

Even better, the package installs MySQL right into the /usr/local/ folder, just like it should.

You might see a prompt asking you “which gem to install for your platform.” Because the mysql gem is updated independently of this article, the versions may change, but your goal will be to pick the very latest “ruby” version listed. So for example, you might see the following list:

You wouldn’t want to select option one because it’s for Windows (“mswin32”). Instead, you’d want to select the second option, “mysql 2.7 (ruby)” which will install the latest standard version for Ruby. It probably wouldn’t hurt to select any of the non “mswin32” versions, actually, but you usually want the latest/greatest option.

We’re Done

Phew! It’s over. We now have a properly located installation of Ruby, Ruby on Rails, MySQL, and LightTPD.