<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>The Official OpenRain Blog &#187; xcode</title>
	<atom:link href="http://blog.openrain.com/tag/xcode/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.openrain.com</link>
	<description>Ruby Web Software Development In Phoenix, Arizona</description>
	<lastBuildDate>Fri, 11 Sep 2009 16:24:24 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Setup Ruby and Rails on OSX</title>
		<link>http://blog.openrain.com/2008/08/20/setup-ruby-and-rails-on-osx/</link>
		<comments>http://blog.openrain.com/2008/08/20/setup-ruby-and-rails-on-osx/#comments</comments>
		<pubDate>Wed, 20 Aug 2008 15:00:49 +0000</pubDate>
		<dc:creator>marc.chung</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[gem]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[port]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[xcode]]></category>

		<guid isPermaLink="false">http://blog.openrain.com/?p=42</guid>
		<description><![CDATA[Welcome to the first of many posts in the OpenRain Tips and Notes series. We&#8217;re going to use this space to share some of the tips, tricks, howto guides, and notes, that we use internally to keep us productive and make us happier programmers.
Today, we&#8217;re going to learn how to get your brand new shiny [...]]]></description>
			<content:encoded><![CDATA[<p>Welcome to the first of many posts in the OpenRain Tips and Notes series. We&#8217;re going to use this space to share some of the tips, tricks, howto guides, and notes, that we use internally to keep us productive and make us happier programmers.</p>
<p>Today, we&#8217;re going to learn how to get your brand new shiny Mac OS X machine setup for Ruby and Ruby on Rails development.  When we&#8217;re done, the full software stack will include <a href="http://www.ruby-lang.org">Ruby 1.8.7</a>, <a href="http://www.rubyonrails.org">Rails 2.1.0</a>, <a href="http://www.mysql.com">MySQL 5.0.51</a>, and <a href="http://mongrel.rubyforge.org/">Mongrel 1.1.5</a>.</p>
<p>And, who might you be? A programmer, comfortable at the command line, running on Mac (Leopard, 10.5.4), and interested in Ruby and Rails.</p>
<h2>Preamble</h2>
<p>Setting up a complete Ruby on Rails environment for local development can be overwhelming, especially if you&#8217;re new to it, but even if you&#8217;re done it before. Depending on your level of comfortability, there several ways you can setup Ruby and Rails on OS X from scratch, so please keep in mind that this guide is one of several &#8220;right&#8221; ways to do this.</p>
<h2>The most &#8220;right&#8221; way to setup Ruby, Rails, MySQL, and Mongrel on your Mac</h2>
<h3>Xcode and MacPorts</h3>
<p><img class="alignnone size-medium wp-image-96" title="xcode" src="http://blog.openrain.com/wp-content/uploads/2008/08/xcode.png" alt="" width="80" height="80" /></p>
<p>Download and install a copy of the Xcode Developer Tools DVD image from <a href="https://connect.apple.com/">Apple&#8217;s Apple Developer Connection</a>.  Membership to ADC is free and highly encouraged if you&#8217;re doing any sort of software development for the Mac.  It&#8217;s a good source for all your Apple programming activities. [Download &gt; Developer tools &gt; Xcode 3.1 Developer DVD (Disk Image)].</p>
<p>Download and install a copy of <a href="http://www.macports.org/">MacPorts</a>.   Since Mac OS X is a descendent of Unix, you can download, compile, and install all sorts of existing Unix software on your Mac.  However, doing this manually becomes tiring almost immediately since you have to manage versions, dependencies, and conflicts all by yourself. The MacPort system is a convenient tool for managing the life-cycle of source-based installations.  Any software that MacPorts installs, is kept separate from the software that comes with your Mac.</p>
<h3>Update your environment variables</h3>
<p>Once MacPort has been properly installed, modify your $PATH and $MANPATH environment variables with the location that MacPorts installs all it&#8217;s software in.</p>
<p>For example, in ~/.bash_profile:</p>
<blockquote><p>export PATH=~/bin:<strong>/opt/local/bin:/opt/local/sbin</strong>:$PATH<br />
export MANPATH=<strong>/opt/local/share/man</strong>:$MANPATH</p></blockquote>
<h3>Ruby, ruby, ruby</h3>
<p><img class="alignright size-medium wp-image-74" title="ruby_logo" src="http://blog.openrain.com/wp-content/uploads/2008/08/ruby_logo.png" alt="" width="94" height="108" /></p>
<p>The good news is that, on Leopard (OS.X 10.5.4), Ruby is an officially supported language.  Out of the box, this includes:</p>
<ul>
<li>the warm fuzzy feeling of Ruby running on OS X</li>
<li>the ability to debug Ruby processes with dtrace</li>
<li>integration with Cocoa via the RubyCocoa bindings, and</li>
<li>using Ruby to control and message OS X applications via the AppleEvent infrastructure</li>
</ul>
<p>The bad news is that updates don&#8217;t flow as fast from Apple so, for instance, running the latest version of Ruby, (1.8.7 as of this writing) isn&#8217;t possible unless you roll your own Ruby and RubyGems environment.</p>
<p>To install Ruby and RubyGems from the command line:</p>
<blockquote><p>$ sudo port install ruby<br />
$ sudo port install rb-rubygems</p></blockquote>
<h3>RubyGems for Rails and everything else</h3>
<p><img class="alignnone size-full wp-image-95" title="rubygems_logo2" src="http://blog.openrain.com/wp-content/uploads/2008/08/rubygems_logo2.png" alt="" width="80" height="80" /></p>
<p>Once you&#8217;ve got RubyGems installed, setting up the rest of your system is easy to do from the command line:</p>
<blockquote><p>$ sudo gem install rails rake capistrano capistrano-ext libxml-ruby mongrel hpricot</p></blockquote>
<p><img class="alignnone size-full wp-image-98" title="rails" src="http://blog.openrain.com/wp-content/uploads/2008/08/rails.png" alt="" width="87" height="112" /></p>
<p>This installs Rails, as well as a bunch of other useful gems into:</p>
<blockquote><p>/opt/local/lib/ruby/gems/1.8/gems</p></blockquote>
<h3>Install MySQL (Option 1: via MacPort)</h3>
<p>There are two options for installing MySQL. Option 1 continues to use MacPort while option 2, a little further down the page, uses the binary installer.  Either option works well.</p>
<p><img class="alignnone size-medium wp-image-91" title="logo_mysql_sun" src="http://blog.openrain.com/wp-content/uploads/2008/08/logo_mysql_sun.gif" alt="" width="205" height="68" /></p>
<blockquote><p>$ sudo port install mysql5 +server<br />
$ sudo -u mysql mysql_install_db5<br />
$ ln -s /opt/local/share/mysql5/mysql/mysql.server ~/bin/mysql.server</p></blockquote>
<p>The first and second command installs and setups MySQL5 via MacPort.  The third command sets up a convenient helper script which you can use to start and stop MySQL server from the command line:</p>
<blockquote><p>$ sudo mysql.server {start|stop|restart|reload|force-reload|status}</p></blockquote>
<p>Optionally, you can configure MySQL to start up automatically when OS X boots.</p>
<blockquote><p>sudo launchctl load -w /Library/LaunchDaemons/org.macports.mysql5.plist</p></blockquote>
<h3>Install the native MySQL driver</h3>
<p>Out of the box, Rails comes with a pure-Ruby MySQL adapter, though all production Rails environments running on MySQL will use the native binary drivers since they are considerable faster.  To get the native MySQL drivers from the command line:</p>
<blockquote><p>sudo gem install mysql &#45;&#45; &#45;&#45;with-mysql-config=/opt/local/bin/mysql_config5</p></blockquote>
<h3>Install MySQL (Option 2: via the binary distribution from mysql.com)</h3>
<p>One alternative to installing MySQL from MacPort is to install the binary distribution from mysql.com.</p>
<blockquote><p><a href="http://dev.mysql.com/downloads/mysql/5.0.html#macosx-dmg">Download</a> and install the DMG.</p></blockquote>
<p>Optionally, you can install the System Preferences panel and a startup script which starts MySQL up along with OS X.</p>
<h3>Install the native MySQL driver</h3>
<p>Similarly, you&#8217;ll also need to configure the MySQL RubyGem driver</p>
<blockquote><p>$ sudo gem install mysql &#45;&#45; &#45;&#45;with-mysql-dir=/usr/local/mysql &#45;&#45;with-mysql-include=/usr/local/mysql/include/ &#45;&#45;with-mysql-lib=/usr/local/mysql/lib/ &#45;&#45;with-mysql-config=/usr/local/mysql/bin/mysql_config</p></blockquote>
<h3>Fin</h3>
<p><img class="alignnone size-medium wp-image-99" title="nacho_libre200" src="http://blog.openrain.com/wp-content/uploads/2008/08/nacho_libre200.jpg" alt="" width="188" height="200" /></p>
<p>That wasn&#8217;t too bad.  If you followed the directions correctly, your shiny new Mac should be properly setup with Ruby 1.8.7 and Rails 2.1.0 running on MySQL 5.0. For performance purposes we also installed Mongrel and the MySQL native drivers which are automatically used by Rails during development.</p>
<p>A super secret cheat sheet:</p>
<blockquote><p>Install <strong><a href="https://connect.apple.com">Xcode 3.1</a></strong><br />
Install <strong><a href="http://www.macports.org">MacPort 1.600</a></strong><br />
sudo port install ruby<br />
sudo port install rb-rubygems<br />
sudo gem install rake rails capistrano capistrano-ext libxml-ruby mongrel hpricot<br />
sudo port install mysql5 +server<br />
sudo -u mysql mysql_install_db5<br />
sudo gem install mysql &#45;&#45; &#45;&#45;with-mysql-config=/opt/local/bin/mysql_config5</p></blockquote>
<a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fblog.openrain.com%2F2008%2F08%2F20%2Fsetup-ruby-and-rails-on-osx%2F&amp;linkname=Setup%20Ruby%20and%20Rails%20on%20OSX"><img src="http://blog.openrain.com/wp-content/plugins/add-to-any/share_save_256_24.gif" width="256" height="24" alt="Share/Bookmark"/></a>]]></content:encoded>
			<wfw:commentRss>http://blog.openrain.com/2008/08/20/setup-ruby-and-rails-on-osx/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
	</channel>
</rss>
