samurai-setup

Created: 2008-10-18 12:05
Updated: 2016-05-08 15:07

README.mdown

Setting up Ruby on Rails Development Environment on Mac OS X Leopard

Please send me your feedback!

This document is written in Markdown. You can use dingus for conversion. TextMate also supports "Markdown to XHTML". See Markdown bundle for details.

Assumptions

  • Mac OS X 10.5 "Leopard" (tested only on Intel-base Macs. Feedback is encouraged from PowerPC users.)
  • Familiarity with basic Unix commands (e.g., cd, ls, sudo, mv, ln, cp, which and whereis)
  • Discuss Mac OS X specific Unix issues
  • This book may be good for Unix beginners
  • Reading ability. MacPorts, TextMate and Ruby do have a good documentation.
  • The primary author of this document (samuraicoder) doesn't know about Windows OS very well.

Overview

We are installing Mac OS X and establish Ruby on Rails development environment. We use MacPorts for installing Ruby. Ruby that comes with Leopard is not the latest anymore. We briefly discuss email setup. We are not installing PHP or Apache since we are using built-in PHP and Apache. You can use vi, emacs or any other text editor you are familiar with instead of mate.

Steps

  1. Establish a wireless connection before installation. Using a wireless connection, you can avoid time to set up a wireless connection first. Take a note of the name of network and password.
  2. Install Mac OS X from the Installer DVD.
  3. Connect to the internet.
  4. Update the OS (e.g., minor updates and security updates) using Software Update. This will require a system restart a few times.
  5. Install Developer Tools (Xcode) from ADC website. (1GB Download)
  6. Install iPhone SDK. Download the package from ADC.
  1. Download and install MacPorts. Read the documentation if you encounter any problems. The documentation is well written.
  1. Download TextMate and install the mate command so that you can invoke TextMate from within the terminal.

Enhanced Terminal Usage

After you've installed mate you can open files and folders with TextMate from within your terminal.

Opening a file

mate FILE

Opening several files

mate FILE1 FILE2

Opening current folder

mate .

Opening specific folder

mate FOLDER/

  1. Write a .bash_login file.

A sample .bash_login file. To make a file, mate ~/.bash_login. After copy-and-pasting code below, hit ⌘-S to save the file. (The file whose name starts with .(dot) are invisible from Finder. Use ls -a to see the files.) The sample file include some code you don't need. It's just an example.

export PATH="/opt/local/bin/:/usr/local/bin:/opt/local/lib/mysql5/bin:/usr/local/sbin:/usr/local/mysql/bin:/Developer/Tools:$PATH" 
export EDITOR='mate -w'
export LANG="UTF-8"
export LC_ALL=en_US.UTF-8
export LC_CTYPE=en_US.UTF-8

# Settings for Ruby installed via MacPorts
TM_RUBY="/opt/local/bin/ruby"


# alias Rails script
alias ss="./script/server"
alias sc="./script/console"
alias sg="./script/generate"
alias sp="./script/plugin"
alias atest="autotest"
alias rakedbm="rake db:migrate"
alias rakedbr="rake db:reset"

# SVN # http://dotfiles.org/~jnunemaker/.bash_profile
alias svnclear='find . -name .svn -print0 | xargs -0 rm -rf'
alias svnaddall='svn status | grep "^\?" | awk "{print \$2}" | xargs svn add'

# GIT based on PeepCode episode by topfunky
alias gst='git status'
alias gl='git pull'
alias gp='git push'
alias gd='git diff | mate'
alias gc='git commit -v'
alias gca='git commit -v -a'
alias gb='git branch'
alias gba='git branch -a'
  1. Check which port if MacPorts is recognized or not. (Troubleshoot: If you get "port: command not found", Read 2.4 of the MacPorts guide carefully.)

Install commands via MacPorts

Install ruby, git, tree and ImageMagick via MacPorts.

sudo port install ruby
sudo port install rb-rubygems
sudo port install git-core +svn
sudo port install tree
sudo port install rb-fxruby # fxruby gem won't work with ruby installed with MacPorts
sudo port install ImageMagick

Note: You may be encountering any errors. In that case, use selfupdate and sync commands, and run clean commands for each port you failed to install as the following. And try installing them once again. You will be repeating the same error until you run clean -all for the failed ports. Installation of a command, which requires sqlite3 is buggy. At this time I'm assuming everyone needs to encounter the bug. Use port clean -all sqlite3(Ask MacPorts list if any problem occurs.)

sudo port selfupdate -D
sudo port sync
sudo port clean -all sqlite3
sudo port clean -all git-core
sudo port clean -all ImageMagick

Install regular applications

  • Install applications of your choice. (e.g., Firefox, VMWare Fusion, Skype, Adium, SuperDuper, NetNewsWire, Knox, Colloquy, 1Password.)
  • Run MobileMe Sync (if you have an account.)

Install gems (including rails)

  • Add a GitHub as a resource for gems. gem sources -a http://gems.github.com
  • Install gems sudo gem install [name_of_gem]. (Don't install MySQL gem yet!)

You can run sudo gem install rails, for example.

Here is a list of gems I use regularly.

  • rails
  • capistrano
  • fastercsv
  • hpricot
  • git
  • github
  • mocha
  • ruby-debug
  • rspec
  • rspec-rails
  • termios
  • sqlite3-ruby
  • will_paginate
  • ZenTest
  • rocv
  • mongrel
  • cheat
  • rmagick
  • mechanize
  • haml
  • autotest
  • redgreen
  • roodi
  • flog
  • reek
  • flay
  • heckle

You can install many gems at once, for example:

sudo gem install rails capistrano fastercsv git github mocha ruby-debug rspec rspec-rails termios sqlite3-ruby will_paginate ZenTest rcov mongrel cheat rmagick mechanize haml.

Note: To check if ImageMagic and rmagick is working properly, refer to http://samuraicoder.net/installing_imagemagick_and_rmagick_leopard.

Set up MySQL

  • Install MySQL gem to make MySQL work better with ruby.

    sudo gem install mysql -- --with-mysql-config=/opt/local/lib/mysql5/bin/mysql_config

Install autotest

TODO

Secure Email

Whatever you do for work, you need to spend less time on email to spend more time on development. You also need to use emails securely.

Using Knox to Secure Email Data on your Drive

TODO: Write about "Why Knox?", "Why not Filevault?" TODO: Some images or screencasts may be necessary.

  • Use Knox and make a new vault called "Mail" (Don't let your login keychain to remember the password. Pick a different password than your login password.Knox is available for €25.

  • Mount the "Mail" vault.

  • Move ~/Library/Mail to ~/Desktop for now

  • Make a symbolic link.

<pre><code>ln -s /Volumes/Mail ~/Library/Mail</code></pre>
  • Then copy all the contents of your "Mail" folder on your Desktop to "Mail" vault.

Certificate and Security

  • Get a free Thawte certificate.
  • Use SSL. If your mail account doesn't support SSL, don't use it. Use https:// instead of http:// if you use a browser to access email.
  • Use IMAP. Gmail or Mailtrust is recommended.
  • Use Passcode Lock in iPhone. If a passcode validation error occurs ten times, all of the content inside the iPhone is autumatically deleted. Read the iPhone Guide (a link to PDF)(This feature is controversial. But Apple fixed a security hole.)
  • Force use of https:// in Gmail. See the image below.

https option

Spam

  • Use SpamSieve for fighting spam. Apple Mail's Junk Filter is not usable. $30.

Navigate without Mouse

Use Mail Act-On for mouse-less navigation. The version 2 supports "open folder". $24.95

Don't Repeat Yourself

Use MailTemplate.

Gem Troubleshooting

Check gem environment

$ gem environment
RubyGems Environment:
  - RUBYGEMS VERSION: 1.2.0
  - RUBY VERSION: 1.8.7 (2008-08-11 patchlevel 72) [i686-darwin9]
  - INSTALLATION DIRECTORY: /opt/local/lib/ruby/gems/1.8
  - RUBY EXECUTABLE: /opt/local/bin/ruby
  - EXECUTABLE DIRECTORY: /opt/local/bin
  - RUBYGEMS PLATFORMS:
    - ruby
    - x86-darwin-9
  - GEM PATHS:
     - /opt/local/lib/ruby/gems/1.8
  - GEM CONFIGURATION:
     - :update_sources => true
     - :verbose => true
     - :benchmark => false
     - :backtrace => false
     - :bulk_threshold => 1000
  - REMOTE SOURCES:
     - http://gems.rubyforge.org/

MacPorts Troubleshooting

Setup TextMate

Moving Windows without Mouse

TextExpander

Mailing Lists

Suggested Readings

  • TODO: Cool enhancements for TextMate such as RubyAmp and ProjectPlus
  • TODO: RSpec bundle (~/.MacOSX/environment.plist)
  • TODO: FastScripts
  • TODO: menubar apps
  • TODO: Installation of "Edit in TextMate"
  • TODO: Email part can be moved to another file.
  • TODO: A brief explanation for what ImageMagick is.
  • TODO: Firefox Setup
Cookies help us deliver our services. By using our services, you agree to our use of cookies Learn more