Set up Ruby on Rails with mySQL on OS X Leopard
I decided to start learning Ruby on Rails, apparently one of the best programming languages/frameworks out there. RoR (Ruby on Rails) comes pre-installed on Leopard, but its not the latest version, and its set up to work with SQLlite, not mySQL, which I want to use.
This tutorial will get you the latest version of Rails and let it work with mySQL. I have another tutorial which covers how to install mySQL.
1 - Ensure you have installed X-code
This won’t work without XCode, so install the correct version first, from the Leopard DVD.
2 - Update Rails on Leopard
To update Rails to the latest version on OS X 10.5 simply open terminal and enter the following command:
sudo gem install rails --include-dependencies
If you want to clean up older versions of rails run this command:
sudo gem cleanup
3 - Install the mySQL Ruby Gem
I only know this works with the MySQL binary installation described here. So be warned!
sudo -s
ARCHFLAGS="-arch i386" gem install mysql -- --with-mysql-dir=/usr/local/mysql
Pick the latest version of mySQL for Ruby when asked :
Select which gem to install for your platform (universal-darwin9.0)
1. mysql 2.7.3 (mswin32)
2. mysql 2.7.1 (mswin32)
3. mysql 2.7 (ruby)
4. mysql 2.6 (ruby)
5. Skip this gem
6. Cancel installation
I picked 3 - mySql 2.7 as thats the latest.
If you suffer issues try this complete guide.
4 - Test it works
- Choose the location you want to put the code for a rails app in - I choose /Sites in my home directory in the following example.
- Navigate to the folder with terminal:
cd Sites - Issue the rails set up command with database parameter:
rails appname --database=mysql - Create a database called appname_development with your preferred tool such as cocoaMySQL
- Ensure there is a user called root without a password, if not, you will need to alter the file at appname/config.database.yml
- Navigate to the appname folder in terminal:
cd Sites/appname - Run:
rake db:migrate - Then startup
ruby script/server - And go to locahost:3000 to see the app in action
If you have some problems, it is likely because the default binary mySQL from the website is not fully compatible at first with Ruby. To fix the problems, check out my post on setting up MySQL on a Mac.
February 22nd, 2008 at 12:21 am
[...] Set up Ruby on Rails with mySQL on OS X Leopard (tags: mysql database mac sysadmin) [...]
June 25th, 2008 at 12:11 pm
Hi Mark, Thanks for this, nice and simple.