<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/css" href="/stylesheets/rss.css"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">
  <channel>
    <title>Ellipsis: Installing Rails on Mac OS X with MacPort</title>
    <link>http://typo.pburkholder.com/articles/2006/11/17/installing-rails-on-mac-os-x-with-macport</link>
    <language>en-us</language>
    <ttl>40</ttl>
    <description>...</description>
    <item>
      <title>Installing Rails on Mac OS X with MacPort</title>
      <description>&lt;p&gt;Yesterday I installed Ruby on Rails on my new(-ish) Intel MacBook.   Last time around I built with a combination of &lt;a href="http://fink.sourceforge.net"&gt;Fink packages&lt;/a&gt; and hand-built applications following &lt;a href="http://hivelogic.com/articles/2005/12/01/ruby_rails_lighttpd_mysql_tiger"&gt;this posting at Hivelogic&lt;/a&gt;&lt;/p&gt;


	&lt;p&gt;This time around I&amp;#8217;ve been using &lt;a href="http://www.macports.org"&gt;MacPorts&lt;/a&gt;, and it&amp;#8217;s making my life much easier.   &lt;a href="http://www.evanweaver.com"&gt;Evan Weaver&lt;/a&gt; got me started with &lt;a href="http://blog.evanweaver.com/articles/2006/06/26/building-ruby-rails-lighttpd-mysql-and-postgres-on-os-x-tiger"&gt;his post on building ruby, rails and associated pieces&lt;/a&gt;, but enough has changed changed since June 26 to merit my own updated take on the process.&lt;/p&gt;


	&lt;h2&gt;Getting started&lt;/h2&gt;


	&lt;p&gt;As Evan notes, &amp;#8220;First, install the Apple Xcode tools from your &lt;span class="caps"&gt;OS X&lt;/span&gt; installation disc&amp;#8221;.  Please do so.&lt;/p&gt;


	&lt;p&gt;Next, install a recent version of &amp;#8220;MacPorts&amp;#8221; (what used to be known as DarwinPorts) from their Subversion respository.  Installing from a .dmg file is easiest, then you can let MacPorts upgrade itself later on.   As of this writing, Ports 1.3.2 is out, but disk images are only available for 1.3.1, e.g. at &lt;a href="http://svn.macosforge.org/repository/macports/downloads/DarwinPorts-1.3.1/DarwinPorts-1.3.1-10.4.dmg"&gt;DarwinPorts-1.3.1-10.4.dmg&lt;/a&gt;&lt;/p&gt;


Next, you&amp;#8217;ll want to update your executable path so the Ports installations in /opt/local are found before your Apple binaries.  You should edit both &lt;code&gt;/etc/profile&lt;/code&gt; and your &lt;code&gt;~/.bashrc&lt;/code&gt; (or equivalent if you&amp;#8217;re using some other shell.  Your path should end up looking something like this:
&lt;pre&gt;
&lt;code&gt;
PATH="/opt/local/bin:/opt/local/sbin:/usr/local/bin:/usr/local/sbin:/bin:/sbin:/usr/bin:/usr/sbin" 
&lt;/code&gt;
&lt;/pre&gt;

	&lt;h2&gt;Install the ports&lt;/h2&gt;


	&lt;p&gt;Now open a terminal (&lt;code&gt;/Applications/Utilities/Terminal&lt;/code&gt;) and run the following:&lt;/p&gt;


&lt;code&gt;&lt;pre&gt;
sudo port -d selfupdate 
sudo port install lighttpd +ssl 
sudo port install rb-rubygems
sudo port install rb-fcgi
sudo port install mysql4 +server
&lt;/pre&gt;&lt;/code&gt;

	&lt;h2&gt;Set up MySQL&lt;/h2&gt;


	&lt;p&gt;You&amp;#8217;ll also need to get mysql4 set up with these commands:&lt;/p&gt;


&lt;code&gt;&lt;pre&gt;
# set up the mysql database:
sudo -u mysql mysql_install_db
# start the server:
sudo /opt/local/bin/mysqld_safe --user=mysql
# set the root password (picking your own password, of course)
/opt/local/bin/mysqladmin -u root password newpassword
&lt;/pre&gt;&lt;/code&gt;

	&lt;p&gt;If you want Launcher to start MySQL automatically on reboot, you can run the following:&lt;/p&gt;


&lt;pre&gt;&lt;code&gt;
sudo launchclt load -w  \
  /Library/LaunchDaemons/org.macports.mysql4.plist
# stop the server
sudo launchctl stop org.macports.mysql4
# start the server
sudo launchctl start org.macports.mysql4
&lt;/code&gt;&lt;/pre&gt;

	&lt;h2&gt;Install the gems&lt;/h2&gt;


	&lt;p&gt;Running gems with the &amp;#8216;-y&amp;#8217; option automatically takes care of prerequisites&lt;/p&gt;


&lt;code&gt;&lt;pre&gt;
sudo gem install -y rails
sudo gem install -y capistrano
&lt;/pre&gt;&lt;/code&gt;

	&lt;h2&gt;Test!&lt;/h2&gt;


	&lt;p&gt;First, are you hitting the right version of Ruby?  &lt;code&gt;ruby --version&lt;/code&gt; should return something like &lt;code&gt;ruby 1.8.5 (2006-08-25) [i686-darwin8.8.1]&lt;/code&gt; &lt;strong&gt;not this&lt;/strong&gt;: &lt;code&gt;ruby 1.8.2 (2004-12-25) [universal-darwin8.0]&lt;/code&gt;&lt;/p&gt;


	&lt;p&gt;Next, can you build a Rails application with&lt;/p&gt;


&lt;pre&gt;&lt;code&gt;
cd ~/tmp
rails widgetapp
&lt;/code&gt;&lt;/pre&gt;

	&lt;p&gt;Okay?  Good.  Now let&amp;#8217;s &lt;code&gt;cd widgetapp&lt;/code&gt; and put the database through it&amp;#8217;s paces.  Save the following code as &lt;code&gt;test_rails_db.sh&lt;/code&gt; (or &lt;a href="/files/testdb.sh"&gt;download it here&lt;/a&gt;)&lt;/p&gt;


&lt;pre&gt;&lt;code&gt;
#!/bin/sh

echo -n "Enter MySQL root password: " 
read PASSWD

mysqladmin -u root -p$PASSWD create widgetapp_development

cat &amp;gt;db/create.sql &amp;lt;&amp;lt;EOF
DROP table if exists widgets;

CREATE table widgets (
    id  int not null    auto_increment,
    name    varchar(40)  not null,
    description   varchar(100)   not null,
    primary key (id)
    );

INSERT INTO widgets (name, description) VALUES ("Tool", "Useful item");
INSERT INTO widgets (name, description) VALUES ("Food", "Tasty stuff");

EOF

mysql -u root -p$PASSWD  widgetapp_development &amp;lt; db/create.sql

mv config/database.yml config/database.yml.dist

cat &amp;gt;config/database.yml &amp;lt;&amp;lt;EOF 

development:
  adapter: mysql
  database: widgetapp_development
  username: root
  password: $PASSWD
  socket: /opt/local/var/run/mysqld/mysqld.sock

EOF
&lt;/code&gt;&lt;/pre&gt;

	&lt;p&gt;and run &lt;code&gt;sh ./test_rails_db.sh&lt;/code&gt;.  Enter your password when prompted.&lt;/p&gt;


	&lt;p&gt;Now the proof is in the pudding.  If the following run s while you&amp;#8217;re in your &lt;code&gt;widgetapp&lt;/code&gt; rails directory, you&amp;#8217;re golden:&lt;/p&gt;


&lt;pre&gt;&lt;code&gt;
script/generate scaffold Widget
script/server
&lt;/code&gt;&lt;/pre&gt;

	&lt;p&gt;Now browse to &lt;a href="http://0.0.0.0:3000/widgets/list"&gt;http://0.0.0.0:3000/widgets/list&lt;/a&gt; and you should utter a little gasp of joy.&lt;/p&gt;</description>
      <pubDate>Fri, 17 Nov 2006 13:08:00 -0800</pubDate>
      <guid isPermaLink="false">urn:uuid:3848e11a-8a2a-44c9-b8df-2f3ad2903c13</guid>
      <author>Peter Burkholder</author>
      <link>http://typo.pburkholder.com/articles/2006/11/17/installing-rails-on-mac-os-x-with-macport</link>
      <category>System Administration</category>
      <category>Ruby and Rails</category>
      <category>ruby</category>
      <category>rails</category>
      <category>lighttpd</category>
      <category>mysql</category>
      <category>macports</category>
      <category>darwin</category>
      <category>darwinports</category>
      <category>macosx</category>
      <enclosure type="application/x-sh" length="800" url="http://typo.pburkholder.com/files/testdb.sh"/>
      <trackback:ping>http://typo.pburkholder.com/articles/trackback/886</trackback:ping>
    </item>
    <item>
      <title>"Installing Rails on Mac OS X with MacPort" by giochi del casino online</title>
      <description>Gioca ai giochi del casino online in un ambiente virtuale sano e sicuro, sapendo di avere accesso a tutti i manuali ed ai libri di strategia, così come alle offerte di Bonus gratuiti e ad altri vantaggi offerti dai casinò online.</description>
      <pubDate>Mon, 03 Dec 2007 18:47:20 -0800</pubDate>
      <guid isPermaLink="false">urn:uuid:e3a29d70-78ed-48c2-947c-512f5821aea5</guid>
      <link>http://typo.pburkholder.com/articles/2006/11/17/installing-rails-on-mac-os-x-with-macport#comment-3970</link>
    </item>
    <item>
      <title>"Installing Rails on Mac OS X with MacPort" by picnic</title>
      <description>there is a typo:

sudo launchclt load -w  \
  /Library/LaunchDaemons/org.macports.mysql4.plist


launchclt - launchctl</description>
      <pubDate>Mon, 03 Dec 2007 09:45:24 -0800</pubDate>
      <guid isPermaLink="false">urn:uuid:a99d186c-8713-446a-a7bb-313f9ed28575</guid>
      <link>http://typo.pburkholder.com/articles/2006/11/17/installing-rails-on-mac-os-x-with-macport#comment-3969</link>
    </item>
    <item>
      <title>"Installing Rails on Mac OS X with MacPort" by punenet.com</title>
      <description>Auf punenet.com können Sie alle Spielregeln für das Spielen im Online Casino nachlesen!</description>
      <pubDate>Tue, 27 Nov 2007 15:32:24 -0800</pubDate>
      <guid isPermaLink="false">urn:uuid:af36467c-a2ae-4fd6-9efc-bf48309cdd2b</guid>
      <link>http://typo.pburkholder.com/articles/2006/11/17/installing-rails-on-mac-os-x-with-macport#comment-3959</link>
    </item>
    <item>
      <title>"Installing Rails on Mac OS X with MacPort" by Shoan</title>
      <description>Thank you for this. You helped me a great deal.</description>
      <pubDate>Fri, 07 Sep 2007 06:05:37 -0700</pubDate>
      <guid isPermaLink="false">urn:uuid:5c0aa2e3-6538-4607-90c9-77980b7a5c9b</guid>
      <link>http://typo.pburkholder.com/articles/2006/11/17/installing-rails-on-mac-os-x-with-macport#comment-3949</link>
    </item>
    <item>
      <title>"Installing Rails on Mac OS X with MacPort" by Shoan</title>
      <description>Thank you this. You helped me a great deal.</description>
      <pubDate>Fri, 07 Sep 2007 06:05:30 -0700</pubDate>
      <guid isPermaLink="false">urn:uuid:9ced2818-cb61-4ace-85a2-fb20008541d2</guid>
      <link>http://typo.pburkholder.com/articles/2006/11/17/installing-rails-on-mac-os-x-with-macport#comment-3948</link>
    </item>
  </channel>
</rss>
