Ruby on Rails
HowtoInstallOnOSXTiger

The tutorial below is out of date. For up-to-date instructions please see one of the following:

Table of contents
  1. Bash Script Auto-Installation
  2. Rubygems Installer Package
  3. Installing with DarwinPorts
  4. Manually fixing Ruby
  5. Where to from here?
  6. MySQL
  7. Comments

1. Bash Script Auto-Installation


Automatically Building Ruby, Rails, Subversion, Mongrel, and MySQL on Mac OS X

A bash script by Sakuzaku to automatically download and install:

Back to top…

2. Rubygems Installer Package

If you already have rubygems installed, simply open a terminal and type:

sudo gem install fixrbconfig; sudo fixrbconfig

Back to top…

3. Installing with DarwinPorts

You can also install the necessary software with DarwinPorts

If you’re impatient, see HowtoInstallOnOSXTigerUsingDarwinPorts for step-by-step instructions on what to do.

First, install DarwinPorts 1.0 (available from their web site) and follow their directions. Once you’ve done that, you can install ruby, rb-rubygems, fcgi, and mysql. There’s also a Portfile for lighttpd available (albeit unofficially).

DarwinPorts has many of the popular extensions for ruby directly available, but for those available in .gem format I prefer to use rubygems. Using rubygems, install mysql, sqlite3 (if you want to use sqlite3 which is now built into Tiger), and rails – and any other gems you wish to use. The following command should work:

gem install mysql sqlite3-ruby rails

(Until the ruby-gems fcgi is updated to 0.8.6 or 0.8.7, you can use this Portfile to install 0.8.6. This is recommended because the gem version has a memory leak.)

Back to top…

4. Manually fixing Ruby

Download the fixed rbconfig.rb here: rbconfig.rb (<—Invalid URL, requires password? Please Update)

Look through it and compare to the current version installed on your system (/usr/lib/ruby/1.8/powerpc-darwin8.0/rbconfig.rb). You can simply copy the fixed version you’ve downloaded to the same location as the apple-installed version by typing:

sudo cp rbconfig.rb /usr/lib/ruby/1.8/powerpc-darwin8.0/rbconfig.rb

But I’m going to assume that if you’ve read this far, you probably want to know why ruby is broken, or want to make the changes yourself. The version of ruby that /Apple has included with Tiger is has a couple of things wrong with it (that we’ve found so far):

  1. rbconfig.rb makes reference to cross-compilation using the -arch i386 compiler flag. This flag does not seem to work when compiling native code extensions for rubygems, and I’d hazard to say the necessary files simply aren’t present in the Tiger developer tools for compiling i386 code on powerpc machines. When the Darwin 8.0 installers are released, it’s entirely likely ix86 users will need to make the opposite change to what we’ve done here and remove all references to -arch powerpc. You may notice that both -arch flags are removed if you simply copied over the fixed rbconfig.rb you downloaded above, or if you installed the Mac OS X Installer Package – the flag is completely unnecessary if you aren’t using a cross-compiler.
  2. rbconfig.rb makes reference to CONFIG["LIBRUBYARG_STATIC"] = "-l$(RUBY_SO_NAME)-static". This won’t work, as Apple has only included the dynamic library libruby.dylib, so you’ll need to change this line to reference nothing: CONFIG["LIBRUBYARG_STATIC"] = "".
  3. Rails’ console (./script/console from within your rails app) doesn’t start because it is missing the readline library. You can install this yourself by installing GNU Readline, and recompiling the readline source in the ruby distribution. I’m not going to walk through that here, because if you don’t know how already you really shouldn’t be trying – just use the installer package at the top of this page.

Back to top…

5. Where to from here?

Once you’ve chosen a path and made the necessary changes/fixes, head back to the standard instructions for “installing Rails under Mac OS X

Back to top…

6. MySQL

Back to top…

7. Comments

There are many, many comments and methods for making MySQL/Ruby work on Tiger. This HOWTO 301289 worked well on a brand new install of OS X 10.4, using MySQL Server 4.1.15 (installed using DarwinPorts).

—John Schult

I would highly recommend using DarwinPorts to install Ruby and any other software you need.

—Russ Smith

What version of MySQL should someone use to run on Tiger? I tried 4.0.24 but this seems to give problems. Is is safe to install 4.1.10 for OSX 10.3 on Tiger?

—Magirus

I’ve used MySQL 5.x and MySQL 4.x under Tiger without incident. Assuming your copy of mysql is installed in /usr/local/mysql you need to type:

sudo gem install mysql -- --with-mysql-dir=/usr/local/mysql

Which will install the ruby mysql bindings for you. If you just run: sudo gem install mysql, you’ll get messages like ‘ERROR: While executing gem … (\RuntimeError) ERROR: Failed to build gem native extension’.

—TonyArnold

I had to install and use the fixrbconfig gem as described above, and install the mysql gem as described above to make Rails apps work correctly. Note that you’ll have to do these two steps in that order; the fixrbconfig gem allows you to build gems locally, which is required for the mysql gem. Takes no more than a couple of minutes to do this stuff.

—AndrewOtwell

Can you please detail the steps you needed to take? This would give novice users a more comfortable way into RoR

—Magirus

Yes, I’ll put together instructions in the next couple of days and post them here. Really, you should give the Mac OS X installer package a go if you haven’t.

—TonyArnold

Except none of this works, because, even after installing the Tiger Ruby fixes, Rails gives an ActiveRecord StatementInvalid “No database selected” error when you try to query the MySQL database, and the ‘gem install mysql’ native build fails if you try to install the native MySQL bindings instead. You’ll probably need to run sudo gem install mysql -- --with-mysql-dir=/usr/local/mysql instead of sudo gem install mysql as noted above. Honestly, I did. Following these instructions exactly, it still fails. The “fresh install” suggestion below is a great idea.

It would really be great if someone could do a fresh install in Tiger… I mean fresh-fresh, as in, do a clean install of Tiger and then do a step by step install of Ruby in its entirety. I’ve had nothing but trouble trying to get Rails going in Tiger and it would be great if an expert did it from scratch (honestly, it would be better if the tutorial didn’t use things like darwinports only because most of the darwinports don’t yet work in Tiger). —GM

Here’s details of install Rails and MySQL on a fresh install of Tiger:

http://jamie.blogthing.com/2005/05/12/installing-rails-on-a-fresh-tiger/

JBRW

If you like me have problems with MySQL being unable to connect with a missing password, even though you’ve updated RoR, triple-checked the database.yml settings and so on, then just make sure that you run the sudo gem install mysql -- --with-mysql-dir=/usr/local/mysql command, and all is working fine.

MGP

I searched all over the web to get Rails on Tiger. I used Jamie’s instructions above to install Rails and I was still getting errors. I finally got it working and this is how I did it:

Installing Ruby on Rails on Tiger

Please let me know if this works for you or if I have to make changes to get it working correctly.

—Jose Marinez

To succesfully install the MySQL gem with Tiger Server (10.4.1), fill in your connection settings in database.yml and run this command: sudo gem install mysql -- --with-mysql-config=/usr/bin/mysql_config

—nicitz

Thank you, nicitz! This fix (above ) was the one that I needed to get the mysql gem installed on Tiger server.

—HazMatt

After much struggling with Tiger and MySQL I realized that mysql wasn’t installed where I thought it was (installed from mysql.com binary). If you type ls /usr/local in the terminal, you can find the real directory. Then, change the install statement. For example, mine is sudo gem install mysql -- --with-mysql-dir=/usr/local/mysql-standard-4.1.12-apple-darwin7.9.0-powerpc

—Daniel Morrison

If you don’t follow the instructions here, you’ll probably run into an error saying Before updating scaffolding from new DB schema, try creating a table for your model when you try to create a scaffold. Hopefully this page will now show up in searches for that phrase now.

AnonymousCoward

If ‘gem install mysql’ if giving you an error 404. Install the Xcode tools from the Tiger DVD. Then download (not 2.6; this wouldn’t compile for me) and follow the installation instructions at http://www.tmtm.org/en/mysql/ruby/
This sorted the Before updating scaffolding from new DB schema, try creating a table for your model error for me.

—dctanner

I recently installed Rails on OS X 10.4.1 using the installer package above (option number 1). I installed MySQL 4.1.12 downloaded from the MySQL.org site. I also installed the other required packages / gems. When I went to test the scaffolding in a basic Rails app, I kept getting an “Access denied” error message. I knew my database.yml settings were correct, and I had the permissions set up correctly in MySQL. I could even log into the db from the Terminal. After 2 days of searching the web and asking in the IRC room, I finally was directed to the Ruby MySQL API module. I installed it, and was off and running. I would add this module to the list of items to install on OS X 10.4. At the very least, keep it in mind if you run into MySQL issues.

—Phil

I did a which mysql and found it to be /sw/bin/mysql… but it still didn’t work until i used /usr/local/mysql

—Bryce

I was getting a strange error ‘ERROR: Error installing gem mysql[.gem]: string contains null byte’ so I forced gems to do a remote install:

sudo gem install -r mysql -- --with-mysql-dir=/usr/local/mysql-standard-4.1.12-apple-darwin7.9.0-powerpc/

and it appears to have worked.

—Ben

I confirm that the above mentionned solution works fine.
To change gcc to v 3.3, type this :
$ sudo gcc_select 3.3

—Thomas Balthazar

Referencing the full directory is probably not needed. The orginal instructions were missing a ’-’, and so it was probably a cut-and-paste error. I changed them from this:

to this:

and it worked for me.

—Tim S.

—Etienne Gonnaud

I had no luck at all with the gems install of mysql [10.4.1 w/ XCode 2.1 and the official MySQL package for 4.1.13, and the system install of Ruby but with rbconf fixed]. Instead, I used the downloadable MySQL/Ruby package (from tmtm.org, linked below) and the --with-mysql-config flag pointing at /usr/local/mysql/bin/mysql_config.

Using mysql_config prevents Ruby from trying to find and verify libmysqlclient.a itself, which wasn’t working.

—Pete Hopkins

For those who followed the above instructions for Tiger and still have the “update Table error” when generating scaffold, I’ve solved this through the MySQL/Ruby package and its proper instructions.



And if you’re still having problems, I have it pretty much step by step how to do it here (including the manual mysql ruby gem install): http://www.pjhyett.com/articles/2005/06/04/setting-up-ror-in-tiger

I was having multiple problems which can be read about on this site:

http://habtm.com/articles/2005/08/04/installing-ruby-mysql-bindings-2-6-on-tiger-troubleshooting

I managed to get this working with Tiger doing the following:

  1. Download ‘mysql-ruby-2.7-beta2’ from http://tmtm.org/downloads/mysql/ruby/
  2. Make sure gcc is using version 4.0:
    
    sudo gcc_select 4.0 
    
  3. ruby extconf.rb --with-mysql-config 

    I got errors, but persist on with it. This should make the Makefile
  4. make 
  5. sudo make install 

I then started up the server for my Rails app, and with scaffolding it now works fine. I’m so glad that it works now. – David Winter


If you keep gettting this:

checking for main() in -lm... yes checking for mysql_query() in -lmysqlclient... no checking for main() in -lz... yes checking for mysql_query() in -lmysqlclient... no checking for main() in -lsocket... no checking for mysql_query() in -lmysqlclient... no checking for main() in -lnsl... no checking for mysql_query() in -lmysqlclient... no

try

sudo gem install mysql -- --with-mysql-include=/usr/local/mysql/include/ --with-mysql-lib=/usr/local/mysql/lib/ --with-mysql-config=/usr/local/mysql/bin/mysql_config

it worked for me.



After getting the “checking for mysql_query()” errors, this worked for me on 10.4.2

sudo gcc_select 3.3
sudo gem install mysql -- --with-mysql-dir=/usr/local/mysql --with-mysql-include=/usr/local/mysql/include/ --with-mysql-lib=/usr/local/mysql/lib/ --with-mysql-config=/usr/local/mysql/bin/mysql_config

Back to top…


libmysqlclient.so missing from MySQL binary


I worked on this for ages, reinstalled Ruby, MySQL and Rails at least three times each and tried to compile the mysql gem with all different varieties above. None worked – either I would get a compilation error (with the—with-mysql-dir variety) or the compilation would seem to go fine, for the Rails server inadvertently then to crash on a “Missing Symbol” error. For a technology promising to bring up web development productivity 10 fold, this was extremely discouraging.

What turned out to be the problem? The compiler needs the libmysqlclient.so (?) mysql library file to build the gem against. But each of the Mac OS X binaries I installed from MySQL .com, are distributed without this library. So no wonder the compiler could not compile successfully: it is missing a key component that is simply not installed when you are following the installation instructions (install the latest MySQL binary) above. I’m wondering why I seem to be the first to notice this?

Anyway, the solution takes a bit more time but is relatively simple. In stead of installing a binary, scroll down the MySQL distribution list and download the source code distribution. Follow the instructions in the INSTALL file to install this copy on your system, just remember to do ‘sudo make install’ in stead of ‘make install’ I even installed it on a different location /opt/mysql so as not to overwrite my standard binary installation on /usr/local/mysql . Afterwards the instructions above (sudo gcc_select … , sudo gem install …) work like a charm and my Ruby on Rails is finally working now. :-)

For the people maintaining the installation packages and gems – has nobody ever noticed that this key libmysqlclient.so file is missing from the MacOSX? binary of MySQL?


I dont understand why you have to install Apple Developer tools. Ruby is already on Mac OS X - out of the box.

-Alex


Problems with MySQL 4.1.13?

I’d been trying to install any mysql connector (2.5, 2.6 & 2.7) over the last week on OS X 10.4.2 with MySQL 4.1.13 and always got either the no mysql.h error (when I tried to install manually with ‘ruby extconf.sh’ etc.) or the checking for mysql_query() in -lmysqlclient… no error when trying to use Gems.

Checking in with another OS X user who’d succesfully installed the connector I found he was using 4.1.12 so I replaced 4.1.13 by shutting down MySQL and using the command line to move the /usr/local/mysql-whichever_version_you’re_running and the mysql symlink into my user directory. Initially, 4.1.12 refused to install which I suspected was due to it finding the installer receipt for .13 in the /Library/Receipts folder so I removed it and .12 went in fine.

Using the Gem method, mysql installed first time even though I still got those checking for mysql_query() in -lmysqlclient… no errors I’d had before.

+ Update +

While this solution worked fine on my Mac Mini it didn’t seem to fix the problem on my office G4 so mileage is definately going to vary!


The difference between the descriptions that work, and the descriptions that don’t work, is that the ones that do work use the 2.7beta2 mysql bindings, and not whatever version gem would use on its own. Using them, I’ve gotten two machines to install a working setup of rails, when several tries before left me with nothing but frustration. READ Tony Arnold’s description here, and follow these instructions:

http://www.tonyarnold.com/articles/2005/08/11/mysql-bindings-for-ruby-under-mac-os-x-tiger



I’ve just found that the suggestions made on this page work only on my machine if I use GCC 4.0, not 3.3 as recommended.

If you’ve just upgraded to Tiger, and you’ve also upgraded MySQL, it’s really worth noting that MySQL4.1+ changes the way it handles passwords. 4.1.x versions of MySQL use a new password hashing function that is not compatible with the older client libraries—in short, the upgrade will break most of your previous (PHP, what have you) apps if you don’t startup MySQL using the—old-passwords option.

I tried to keep a running list of the individual problems and their causes as I went along:

http://www.evilrob.org/journal/archives/000198.html

Hope this helps you if something about your config isn’t right. It’s no new magic steps in fixing things that aren’t on this page, but it does have each problem and it’s cause. And I think I hit all the problems. :-)

With 10.4.3 and Xcode 2.2 (November 10, 2005), several file locations have changed. Native extensions won’t build; you can fix this by adding symlinks to the old locations.

sudo ln -s /usr/lib/ruby/1.8/universal-darwin8.0/* /usr/lib/ruby/1.8/powerpc-darwin8.0

This probably calls for another fix to rbconfig.rb – I’ll add it to the Mac OS X installer package—it’d be good to get the ‘fixrbconfig’ gem updated too.

TonyArnold

If you’re looking for a step-by-step install (from source) of ruby, rails, lighttpd, and their pre-requisites, hivelogic has just put up a post here: http://hivelogic.com/articles/2005/12/01/ruby_rails_lighttpd_mysql_tiger

Romain BOSSUT

I made an all-in-one install package of RubyOnRails on Mac OS X.
This Package provides :
Apache 2.2.0 (with mod_rewrite and mod_fastcgi, ruby on rails ready)
PHP 5.1.2
MySQL 5.0.20a
PostgreSQL 8.1
and .. Ruby On Rails 1.1.2 :-)

WebServerXKit


Does anyone have any advice on installing Ruby and/or rails using fink?



There is a ton of wrong, semi-wrong, misleading, and inaccurate information on this page. Most of the so-called fixes only work for a specific combination of software, or are simply covering up the real problem. I recommend that there be a single “official” setup of RoR for each platform, so that, if nothing else, we can reduce the amount of conflicting information on this page.

I totally agree. If someone could go through and label this stuff it’d be great. Dates / config / version information would also be nice.

I’m doing a writeup of a Darwin Ports install that I’ll be testing tonight. If that works well I’ll get it posted somewhere because it’ll be more recent than a lot of the info that is floating around which is inaccurate, old, or misleading.


Please do. That would be appreciated. I would suggest having here a little background info on the UNIX’ness of Mac OS X that relates to the components being installed. Questions such as what is Darwin Ports or Fink might be common knowledge to experienced developers but not to new Mac OS X users. It’s really hard to follow all the “type this and run this” kind of instructions without having to know the concepts.


Here is a KISS way to install RoR:
1. Download & install this package : http://rubyosx.rubyforge.org/
2. Bring in a terminal and type: sudo gem install rails—include-dependencies
3. Done!