1
2
3
4
5
<h1>hello world</h1>

Install Ruby on Rails using MacPorts

Sandbox

Much of what I’ve done is based on the work of Dan Benjamin at Hivelogic. Whether you compile manually (as Dan suggests) or use MacPorts, the goal is the same—to create a sandbox for your Ruby on Rails environment.

These instructions are meant to be quick and to the point. I won’t be going into great detail as to why I’ve done what I’ve done.

XCode

Be sure to install XCode tools from the Leopard installation DVD.

MacPorts

Download the latest version of MacPorts and install.

Bash

Update .bash_profile:

mate ~/.bash_profile

Add these lines:


export PATH="/opt/local/bin:/opt/local/sbin:$PATH" 
export MANPATH="/opt/local/share/man:$MANPATH" 

Log out of the terminal session and begin a new one so the changes take hold.

MySQL

Install MySQL:

sudo port install mysql5 +server

Initialize MySQL database:

sudo mysql_install_db5 --user=mysql

Install MySQL 5 startup:


sudo launchctl load -w /Library/LaunchDaemons/org.macports.mysql5.plist

For convenience, create a mysql link to mysql5 binary:


cd /opt/local/bin
sudo ln -s ../lib/mysql5/bin/mysql mysql

Secure MySQL

sudo mysql_secure_installation5

  1. Hit enter for current root password (because one hasn’t been set, yet)
  2. When it asks if you want a root password, it’s up to you. A development machine probably doesn’t need one.
  3. Yes, you do want to remove anonymous users
  4. Yes, you want to disallow root login remotely
  5. Yes, remove test database
  6. Yes, reload privilege tables now

More ports to install


sudo port install git-core +svn +bash_completion
sudo port install freeimage
sudo port install ruby
sudo port install rb-rubygems
sudo port install rb-termios
sudo port install rb-mysql

Bash completion for git

cp /opt/local/etc/bash_completion.d/git ~/.git_bash_completion

Add source ~/.git_bash_completion at the very bottom of ~/.bash_profile.

GEMs

Right now the MacPorts comes with an older version of rubygems. So first you should upgrade it.


sudo gem list -r
sudo gem update --system

There are a fair number of GEMs to install. I personally don’t use the generated rdoc and ri documentation. To install all the GEMs at once—put this in as one long line:

sudo gem install --no-ri --no-rdoc rake rails capistrano mongrel redgreen test-spec RedCloth pdf-writer ZenTest ruby-debug haml rcov image_science flexmock rr

SuperRedCloth

SuperRedCloth is intended to eventually replace RedCloth which has several annoying parsing errors. Installing SuperRedCloth causes a lot of memory use during compilation.


sudo port install ragel
sudo gem install --no-ri --no-rdoc superredcloth --source http://code.whytheluckystiff.net

A 256MB slice on slicehost took a LONG time to install the gem. I had to disable the mongrels so there would be enough memory.

SuperRedCloth is under active development so it pays to keep the gem up-to-date. According to the SuperRedCloth Wiki, the gem is always a few days behind. So compiling from source may be useful:


svn co http://code.whytheluckystiff.net/svn/redcloth/branches/superredcloth superredcloth
cd superredcloth
rake
rake gem
gem install pkg/superredcloth-1.###.gem

Rails assumes that you are using RedCloth when you run the textilize command. So you need to load this code into helpers/application_helper.rb:


  def textilize(text)
    require_library_or_gem "superredcloth" unless Object.const_defined?(:SuperRedCloth)
    if text.blank?
      "" 
    else
      textilized = SuperRedCloth.new(text)
      textilized.to_html
    end
  end

Test Spec on Rails

A useful companion plugin for the test_spec gem is TechnoWeenie’s test_spec_on_rails. To add it to an existing Rails project, change directories to the Rails project root. Then install the plugin:

./script/plugins install http://svn.techno-weenie.net/projects/plugins/test_spec_on_rails/

Require in test_helper:

require 'test/spec/rails'

Changelog

  • Friday, 4 April 2008, 8:44 AM – Added ‘rr’ to gem install list.
  • Monday, 14 April 2008, 1:24 PM – Updated git-core install to include subversion variant and bash completion. Added git bash completion as recommended by Pratik Naik.