The tutorial below is out of date. For up-to-date instructions please see one of the following:
A bash script by Sakuzaku to automatically download and install:
If you already have rubygems installed, simply open a terminal and type:
sudo gem install fixrbconfig; sudo fixrbconfig
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.)
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):
-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.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"] = ""../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.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
which mysql” to find out where your mysql installation is. locate mysql_config” to see where your mysql_config binary is.sudo gcc_select 3.3” before installing the gem. (Don’t for get to switch back after.)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.
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:
sudo gem install mysql -- -with-mysql-dir=/usr/local/mysqlto this:
sudo gem install mysql -- --with-mysql-dir=/usr/local/mysqland 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.
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:
sudo gcc_select 4.0
ruby extconf.rb --with-mysql-config
make
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
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
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
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.
TonyArnoldRomain 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 :-)
Does anyone have any advice on installing Ruby and/or rails using fink?
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!