Install MySQL, Ruby, Rails, and Mongrel with MacPorts
about 1 year ago
MacPorts makes it simple and easy to install the latest versions of all the tools you need for Rails development. It conveniently keeps them separate from the ones that come with OS X, so things that depend on the OS X versions won't break, and you can remove them again anytime you like. This guide will walk you through the installation process.
Installing MacPorts
First, make sure you've got XCode installed. You'll find the installer on your OS X install disks.
Next, go to the MacPorts download page and grab the .dmg file that corresponds to your version of OS X. Go ahead and run the installer.
Once that's done, open Terminal and type:
touch .bash_profile
open .bash_profile
This will pop open a TextEdit window. Add the following two lines to the end of the file and save it (it may be empty to start with):
export PATH=/opt/local/bin:/opt/local/sbin:$PATH
export MANPATH=/opt/local/share/man:$MANPATH
Now go back to Terminal and type:
source .bash_profile
What have you just done? MacPorts has created an /opt/local folder under which it will install any software you ask it to. The lines you added to your .bash_profile file ensure that when you run something like ruby in the Terminal, your shell can find the MacPorts installed version, and, importantly, find it before the regular OS X one.
Installing Everything Else: The Lightning Version
Here are all the commands you need to run in the Terminal to install Ruby, MySQL, Rails, and Mongrel:
sudo port install ruby
sudo port install rb-rubygems
sudo port install mysql5 +server
sudo -u mysql mysql_install_db5
sudo launchctl load -w /Library/LaunchDaemons/org.macports.mysql5.plist
sudo port install rb-mysql
sudo gem install -y rails
sudo gem install -y mongrel
Step By Step
Here's the same thing again, step by step with some more details.
Install Ruby with:
sudo port install ruby
You'll be asked for your password. Port will take a while to run; it's building Ruby from source.
Next install RubyGems with:
sudo port install rb-rubygems
RubyGems will let you install things like Rails later on.
Install the MySQL 5 server:
sudo port install mysql5 +server
Set up MySQL's default databases:
sudo -u mysql mysql_install_db5
Start MySQL and ensure that it starts automatically when you restart your Mac:
sudo launchctl load -w /Library/LaunchDaemons/org.macports.mysql5.plist
Install the Ruby MySQL library:
sudo port install rb-mysql
Install Rails and everything it depends on:
sudo gem install -y rails
Install Mongrel, so Rails will run a bit more nicely:
sudo gem install -y mongrel
That's it! You now have your own copies of Ruby, Rails, MySQL, and Mongrel all ready to go.
Comments
Date: 16 June 2008: I have Mac OSX 10.5.3 Leopard. I installed macports. I started Terminal and ran the bash shell and set the $PATH var correctly. I the followed the instructions and typed: sudo port install ruby and entered my user password which has Admin rights.
and after 10 minutes, got Error in build - last 20 odd lines:
NOW WHAT ???
Thanks a lot. Have been using hivelogic procedure for a long time. I am thinking of moving over to this, since I use a lot of macports, and the PATHs often conflict.
Andy, this is a macport activation issue. Google the error message. I recently had something similar and had to just force an activation with a force switch, can't remember since I am not a geek :-(. I think you will find the answer on googling the error.
same error as Andy. :-(
See the comments on this ticket. Something has created an /opt/local/bin/captoinfo when it shouldn't have. You should try moving this file out of the way.
Pete, Thank you so much, it installed without a single problem. Couldn't have been easier! Love your work! Cheers
One important thing to note about MacPorts Ruby is that it install 1.8.7, which does have API level changes over 1.8.6. Just be aware of this if you are deploying or depending on 1.8.6 for production work.