Super Simple Ruby on Rails Install with MacPorts (for Leopard)
Update: Since Rails 2.0.2 has been released rails setup on leopard has been greatly simplified, check out my new guide here: teabass.com/rails-on-leopard-the-right-way
So Apple’s newest Version of OS X is here, Leopard and it rocks! Stacks, Spaces, Timemachine and all the other little features and improvements make it the best OS to date, if you haven’t already got it what are you waiting for?!
One of the most awesome, although not so widely know improvements in Leopard is that it comes with Ruby on Rails installed right out of the box!
This guide is to help you set up the perfect development environment for developing Ruby on Rails Web apps giving you everything you need and making it easy to stay up to date with the latest versions.
I’ve taken my previous guide for setting up OS X 10.4 Tiger and tweaked it for Leopard plus added some optional extras on the end too.
The 8 step Guide
So lets assume that you have a brand new mac or a clean install of Leopard and dive straight in:
-
Install X11 - You’ll find this on your Leopard disc that came with your mac or download from Apple
-
Install Xcode Tools - Again on the Leopard disc with your mac or you can download the latest version from ADC
-
Install Macports - Download Macports and run the installer (1.5.0-10.5 for Leopard at the time of writing)
-
Add macports to your Terminal - Since macports gets installed in /opt/ you’ll need to add the path to your terminal config so you can use it.
Open ~/.bash_profile with your favourite texteditor and add this line to the bottom of the file:
PATH="/usr/local/bin:/usr/local/sbin:/bin:/sbin:/usr/bin:/usr/sbin:/opt/local/bin:/opt/local/sbin"and then save the file, close it and restart your terminal.
-
Check for macports updates - in your terminal type:
sudo port selfupdate -
Install MySQL - Ruby, RubyGems, Rails and Subversion come pre-installed with Leopard so we’ll get straight to MySQL. This is the one that usually causes the headaches, put these commands into the terminal:
sudo port install mysql5 +serversudo launchctl load -w /Library/LaunchDaemons/org.macports.mysql5.plistsudo mysql_install_db5 --user=mysqlcd /opt/local ; sudo /opt/local/lib/mysql5/bin/mysqld_safe &sudo ln -s /opt/local/var/run/mysql5/mysqld.sock /tmp/mysql.sockOptional: I like to set my self up as a user so I can get into mysql a little quicker put this into the terminal:
mysql5 -u rootThen excute this sql statement (you’ll need to change the name andrew to your Leopard username):
GRANT ALL PRIVILEGES ON *.* TO 'andrew'@'localhost';I didn’t include a password in the previous command because i’m only using my databases locally for development, if you want a password use this command (replace andrew with your username and some_pass with your password):
GRANT ALL PRIVILEGES ON *.* TO 'andrew'@'localhost' IDENTIFIED BY 'some_pass' WITH GRANT OPTION; -
Install Ruby’s MySQL adaptor - One last port install:
sudo port install rb-mysql -
Update Installed Gems - Leopard comes with a load of gems pre-installed including rails and capistrano, we’ll just check they are up to date:
sudo gem update
Now your ready to get started developing Ruby on Rails applications on Leopard.
Optional Extras
You don’t have to install these pieces of software, but they will make your life easier if you do and most of them are completely free!
-
RMagick - If you want to do any image processing, RMagick is a good place to start, you can install it using the command below:
sudo port install rb-rmagickWorks great with the attachment_fu and fleximage plugins.
This post might help too: http://nullstyle.com/2007/10/27/how-to-build-imagemagick-and-install-rmagick-with-macports-on-mac-os-x-leopard/
- CocoaMySQL - A nice GUI front end for MySQL databases to save you sql related headaches later one.
- Textmate - The best text editor in the world! We’ll I think so anyway, it has some great bundles that take the leg work out of any typing, especially good with Rails.
- iTerm - A replacement Terminal that does some neat extra stuff.
- Firefox - The Daddy of Web browsers and the best one of the bunch for web development, mainly due to the awesome plugins and extensions you can get for it like: Web Development Toolbar, Firebug, Yslow, View Source Chart and MeasureIt




[…] Update: If you are using OS X 10.5 Leopard you’ll want to use this guide instead: Teabass.com/super-simple-ruby-on-rails-install-with-macports-for-leopard […]
Teabass - Andrew Nesbitt's Blog » Super Simple Ruby on Rails with MacPorts on November 4, 2007 1:52 pm
I guess I will follow these steps since I purchased Leopard!
Summer OrdoƱez on November 4, 2007 6:17 pm
You just gave me a good reason to try to install OSx86 on my Dell Latitude D600. I wonder how well i’ll work on a Pentium M with a 1.6 GHz CPU though. :/
nitro2k01 on November 4, 2007 6:18 pm
It’ll run… But you might wanna turn of some of the eye candy
Stock up on RAM and you’ll be ok
Kuyler McComas on November 4, 2007 11:51 pm
Well apparently 10.5 fixes some multi-threading issues that 10.4 was having, so you should in theory get a performance increase when using multiple applications
Jason Green on November 6, 2007 3:48 pm
I’ve updated step 6 so it works better, enjoy
Andrew on November 6, 2007 4:13 pm
You may find the rubygems is missing so you might need to reinstall that:
sudo port install rb-rubygemsAndrew on November 6, 2007 4:57 pm
This is very useful, thank you Andrew
Remi on November 10, 2007 1:35 pm
Hey Andrew, thanks!
I was developing Rails on Windows but just jumped to a MacBook with Leopard
Those tips are really usefull for me! I will appreciate also another tip: do you use a nice Mac GUI front end for Subversion? See you,
Thiago L. Christofoletti on November 11, 2007 11:21 am
http://www.versionsapp.com/ is gunna be awesome when it is released, but for now I use textmate’s built in Subversion client since it fits nicely with my workflow
Andrew on November 11, 2007 11:33 am
Thanks again Andrew. So I will try textmate’s built in client. Versions is a nice promise
Hope to get the beta soon.
Thiago L. Christofoletti on November 11, 2007 12:30 pm
Thanks for posting this, it was impossible to find a good leopard tutorial.
It also went surpisingly smoother then tiger and considering all the other posts just said how hard it was on leopard.
dmix on November 12, 2007 5:55 pm
[…] Read the rest of this great post here […]
apple » Super Simple Ruby on Rails Install with MacPorts (for Leopard) on November 17, 2007 7:17 am
Thanks for the tutorial but I ran into a few small hiccups.
After the install I tried to start up mongrel and was told that ruby-gems wasn’t installed. So I did what your extra instructions said and installed ruby-gems again using macports. Then I tried running the server again and I was told to use gems to reinstall rails 1.2.3. So I did that and all works fine, yet in essence I’ve just used two packet repos to reinstall all the software that was already built into Leopard. Just wondering if you had to do this as well or is there a better method of going about this?
M Biel on November 19, 2007 2:48 am
I had that problem too, but I’ve not had time to sort out a more elegant solution unfortunately.
I would guess you could change the current install of rubygems to point to the reinstalled version of ruby, otherwise installing mysql from a binary rather than macports might be the way to go.
Andrew on November 25, 2007 8:27 pm
man this has been one hell of a journey. first of all under 4.) you say that you need to paste the correct paths into ~/.profile. well actually it ~/.bash_profile. so i installed everything over again and now it works pretty fine. hopefully my tables will survive the next reboot.
patrick on November 26, 2007 6:54 pm
Ok, fixed that patrick, thanks
Andrew on November 27, 2007 12:00 pm
sudo port install rb-rubygems gives me an error. It is trying to install version 0.9.5. Is that broken in MacPorts? Which version of rb-rubygems have you installed?
Raymond Law on November 30, 2007 7:08 pm
I’ve finished all the install and can create a rails project but I can’t get the server to run. I get the following error -
./script/../config/boot.rb:18:in `require’: no such file to load — rubygems (LoadError)
from ./script/../config/boot.rb:18
from script/server:2:in `require’
from script/server:2
Can anyone help?
Damian on December 8, 2007 5:10 pm
Nice tutorial, but can not get it to work, since I get the following message :
ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/opt/local/var/run/mysql5/mysqld.sock’ (2)
when doing the optional stuff on step 6
What is going wrong … ??
Branko on December 10, 2007 10:17 am
Hi, I have one problem with MySQL, whenever I reboot my machine I must recreate the symbolic link for /tmp/mysql.sock … anybody has this problem too? How to solve that?
Erik Gyepes on December 17, 2007 8:34 pm
This is an awesome guide. I’m having one problem: when I run sudo gem update, I get this error:
Please set RUBY_SOURCE_DIR to the source path of ruby 1.8.6 (2007-09-23)!
Any thoughts?
David T on December 24, 2007 8:38 am
[…] My last tutorial has caused some people a few headaches, mainly due to mysql not installing properly and because it was using macports ruby and rubygems were recompiled and meant all your gems had to be installed too. […]
Teabass - Andrew Nesbitt's Blog » Rails on Leopard (The right way) on January 6, 2008 5:28 pm
Hi, Great tutorials, keep them up!.
i’ve just screwd up my rails setup, so i’m trying to start from the beginning (done the first steps)..
cognaught:~ matt$ cd /
cognaught:/ matt$ cd opt/
cognaught:opt matt$ sudo ~/.bash_profile
Password:
sudo: /Users/matt/.bash_profile: command not found
what dyou recon??.
Matt on January 8, 2008 7:35 pm
Hello, Can you please tell me where ~/.bash_profile is located? Step 4 indicates that ~/.bash_profile has to be updated. I simply can’t find ~/.bash_profile.
Any help would be appreciated.
Thank you,
Tony
Tony Ventura on February 14, 2008 12:26 pm
If .bash_profile or .profile doesn’t exist then you can make the file using:
nano .bash_profileAndrew on February 14, 2008 12:31 pm
Thank you tip Andrew. I think the real issue is that I don’t understand the lower-level infrastructure that surrounds these Terminal type commands. There must be great tutorial somewhere that explains these commands.
Thank you,
Tony
Tony Ventura on February 14, 2008 2:00 pm
This might be useful: http://www.macdevcenter.com/pub/a/mac/2004/02/24/bash.html
Andrew on February 14, 2008 2:32 pm
The article seems to be exactly what I need.
Thank you,
Tony
Tony Ventura on February 15, 2008 4:55 am
I’m very new to the world of RoR. For that matter I’m a unix newb also. But I wanted to say thx for this excellent tutorial. I had some trouble with #4 but dug around some forums to tell me how to create .bash_profile in your user directory and then put path variables in there…
Also man thx for including “Optional Extras” there at the end, b/c that really helped out.
Sam Wilson on June 30, 2008 4:18 pm