iDevelopSoftware

Simplicity and Clarity by Design

Notes on Setting Up a Ruby on Rails Environment for Ubuntu 10.04.1 LTS

Clone virtual machine

Boot up, open terminal window and run the following commands in order to configure network. (Updates the MAC address for the virtual network adapter.)

# rm -fr /etc/udev/rules.d/70-persistent-net.rules
# shutdown -r now

Packages to install…

sudo apt-get install vim
sudo apt-get install build-essential
sudo apt-get install curl
sudo apt-get install zlib1g-dev
sudo apt-get install libssl-dev
sudo apt-get install libreadline5-dev
sudo apt-get install sqlite3 libsqlite3-dev sqlite3-doc
sudo apt-get install libxml2 libxml2-dev libxslt1-dev
sudo apt-get install libyaml-dev
sudo apt-get install postgresql-8.4 postgresql-client  postgresql-client-8.4 postgresql-doc-8.4
sudo apt-get install postgresql-server-dev-8.4
sudo apt-get install pgadmin3
sudo apt-get install libcurl4-openssl-dev
sudo apt-get install git-arch git-doc git-csv git-svn git-email git-daemon-run git-gui gitk gitweb
sudo apt-get install ssh subversion libgssapi-perl libio-socket-inet6-perl rssh molly-guard
sudo apt-get install openssh-blacklist openssh-blacklist-extra socklog-run
sudo apt-get install rdist makejail subversion-tools db4.8-util

sudo apt-get install autoconf autoconf2.13 autoconf-archive gnu-standards autoconf-doc libtool gettext gettext-doc libtool-doc

sudo apt-get install ruby
sudo apt-get install ruby1.8 ruby1.8-dev rubygems1.8 ruby1.8-examples ri1.8 rubygems-doc graphviz graphviz-doc

sudo apt-get install flex bison bison-doc

Setting up RVM

# System Wide RVM Installation
bash < <( curl -L http://bit.ly/rvm-install-system-wide )

# Setup of user defaults
edit /etc/adduser.conf
 - enable the EXTRA_GROUPS stuff and make sure the user is added to the 'rvm' group
edit /etc/skel/.bashrc to add the necessary RVM initialization stuff

sudo su -
rvm install ruby-1.9.2-p0

rvm install ruby-1.9.2-head

(notes on config of Postgres on Ubuntu https://help.ubuntu.com/community/PostgreSQL)

curl ftp://ftp.ruby-lang.org:21//pub/ruby/1.9/ruby-1.9.2-p0.tar.gz > ruby-1.9.2-p0.tar.gz
tar xvf ruby-1.9.2-p0.tar.gz

cd ruby-1.9.2-p0
./configure --prefix=/usr/local/ror --enable-shared
make
make test
sudo make install

Create a file called /usr/local/ror/ror_env.sh. Add the following to it:

export PATH=/usr/local/ror/bin:$PATH

Run the command

sudo ln -s /usr/local/ror/ror_env.sh /etc/profile.d/ror_env.sh

Log out / Log in

Open a terminal window

$ which ruby
/usr/local/ror/bin/ruby
$ which gem
/usr/local/ror/bin/gem
sudo su -
gem update --system
gem install rails -v 3.0.3
gem install sqlite3-ruby
gem install pg
gem install passenger
passenger-install-nginx-module --prefix=/usr/local/ror --auto-download --auto

Git Cheat Sheet

After watching from the side lines for a few years as git gathered a following I finally made the switch out of necessity as a result of doing more projects in Ruby on Rails. The projects I work on are all hosted in the cloud (Heroku, Engine Yard, or directly on Amazon EC2). Many of the tools I use support direct deployment from git. So I now find myself migrating all of my projects from subversion to git.

I tend to write down a lot of notes as I learn a new technology or tool. The migration to git is no different. What is different is how GitHub (the hosted git solution I am using) makes it possible to record just about anything in what they call a gist. This is turning out to be a very useful tool for me. It is a great place to store little bits of code or notes.

Adding MongoDB to My Mac OS X Snow Leopard Ruby on Rails Environment

Tonight I wanted to add MongoDB to my Mac OS X Snow Leopard Ruby on Rails Environment. Refer to my earlier post for details of how I setup my environment. This post assumes your environment is setup according to the instructions found there.

I wrote the following script to handle installation of MongoDB. I decided to grab the pre-built version of MongoDB from the project site and then place the files under the /usr/local/ror directory tree.

#!/bin/bash

# Get and extract a copy of Mongodb
curl http://fastdl.mongodb.org/osx/mongodb-osx-x86_64-1.6.4.tgz > mongodb-osx-x86_64-1.6.4.tgz
tar xvf mongodb-osx-x86_64-1.6.4.tgz

curl http://downloads.mongodb.org/docs/mongodb-docs-2010-09-23.pdf > mongodb-docs-2010-09-23.pdf

# Move files into final locations
(
    cd mongodb-osx-x86_64-1.6.4
    sudo cp -R * /usr/local/ror
    sudo chmod a+r /usr/local/ror/GNU* /usr/local/ror/README* /usr/local/ror/THIRD*
    sudo gem install mongo
)

(
    sudo cp mongodb-docs-2010-09-23.pdf /usr/local/ror/share/doc/mongodb.pdf
    sudo chmod a+r /usr/local/ror/share/doc/mongodb.pdf
)

Download the script tarball (mongodb.sh.tar), extract it into a folder like /tmp and then run sh ./mongodb.sh. This will download the MongoDB binaries and place everything in the /usr/local/ror tree.

One final step. Since you are running on a Mac you might want to check out a cool MongoDB client called MongoHub. You can learn more and download it from the official site.

Setting Up My Snow Leopard Ruby 1.9.2, Ruby on Rails 3.0, Nginx, Passenger Development Environment

Snow Leopard ships with Ruby 1.8.7 installed and an older version of Ruby Gems. I am planning on doing some projects with Ruby on Rails and wanted to setup a current environment. My requirements were:

  • Ruby 1.9.2
  • Rails 3.0
  • PostgreSQL 9.0
  • Nginx
  • Passenger

You should download and install the Mac version of PostgreSQL 9.0 from the folks at EnterpriseDB. You will need to register on the site in order to do the download. Be sure to download PostgreSQL 9.0.1, not one of their Plus packages. It is a nicely packaged installer for the freely available version of Postgres.

Once you install this software you should have a file called pg_env.sh in the /Library/PostgreSQL/9.0/ directory. This file should be added to your /etc/profile. Here is an example of what mine looks like:

# System-wide .profile for sh(1)

# This has to be set to something in order for path_helper (below)
# to update it with paths found in the /etc/manpaths.d directory.
MANPATH=/usr/local/share/man; export MANPATH

# Setup the PostgreSQL environment.
. /Library/PostgreSQL/9.0/pg_env.sh

if [ -x /usr/libexec/path_helper ]; then
    eval `/usr/libexec/path_helper -s`
fi

if [ "${BASH-no}" != "no" ]; then
    [ -r /etc/bashrc ] && . /etc/bashrc
fi

Be sure to log out and log back in before continuing with these instructions. This is important to make sure your PostgreSQL environment variables are set properly.

One of my goals with this setup is to keep everything independent of the default tools that ship with Snow Leopard. To do this I decided that all of my Ruby on Rails setup will be located in the /usr/local/ror directory tree. Here is a script I developed to setup my Ruby on Rails development environment.

#!/bin/bash

# Get and extract a copy of LibYAML
curl http://pyyaml.org/download/libyaml/yaml-0.1.3.tar.gz > yaml-0.1.3.tar.gz
tar xvf yaml-0.1.3.tar.gz

# Build LibYAML
(
    cd yaml-0.1.3
    ./configure
    make
    sudo make install
)

# Get and extract a copy of Ruby 1.9.2
curl ftp://ftp.ruby-lang.org:21//pub/ruby/1.9/ruby-1.9.2-p0.tar.gz > ruby-1.9.2-p0.tar.gz
tar xvf ruby-1.9.2-p0.tar.gz

# Build Ruby 1.9.2
(
    cd ruby-1.9.2-p0
    ./configure --prefix=/usr/local/ror --with-arch=x86_64 --enable-shared
    make
    make test
    sudo make install
)

# Update Ruby Gems
sudo gem update --system

# Install Gems
sudo gem install rails
sudo gem install sqlite3-ruby
sudo gem install pg
sudo gem install passenger

# Configure Passenger for Nginx (downloads Nginx and PCRE automatically)
sudo passenger-install-nginx-module --prefix=/usr/local/ror --auto-download --auto

Download the script, un-tar it and place it in any directory you want. I call the script doit.sh, but you can name it anything you like. Run the script using the command shown below.

$ sh ./doit.sh

Once the script completes you need to add /usr/local/ror/bin to your path. I did this by editing my /etc/paths file. Here is a copy of the file on my machine:

usr/local/ror/bin
/usr/local/bin
/usr/bin
/bin
/usr/sbin
/sbin

One more logout/login and you are done. Have fun playing with Ruby on Rails on your Mac!

Heading to Big Nerd Ranch Later This Month!

One of the podcasts I listen to on a regular basis is called MacBreak. The hosts are Leo Leporte, Alex Lindsay, Andy Ihnatko and a rotating list of other Mac/Apple/iOS luminaries. If you aren’t familiar with it head over to http://twit.tv/mbw and have a listen. It is highly recommended for anyone interested in all things Macintosh (and iOS too).

A few episodes ago Alex Lindsay mentioned that his company was going to be hosting a one week Commuter iOS Class at their San Francisco offices so their team could come up to speed developing applications for iOS devices. The class would be taught by the folks from Big Nerd Ranch. Usually the BNR folks teach classes from their monastery at a secret location just outside Atlanta, Georgia. Having them venture out to San Francisco; wow, what an opportunity. Oh, did I mention that Alex Lindsay also announced that there were a limited number of spots open to the unwashed masses to attend and the class would be held from 2:00 p.m. until 10:00 p.m. each day so folks could continue to do at least part of their day jobs.

All in all this just sounded too good to pass up so I fired off an e-mail to the folks at BNR to let them know I wanted to attend. My fingers were crossed because I know how quickly their classes fill up. Needless to say I wouldn’t be writing this post if I didn’t get in. :-)

So, I’m off to the Pixel Corps offices later this month to soak up some more iOS goodness. Hope to see a few of you there too.

BTW: Here is a link to the course description for anyone curious.

MacBook Pro Development Environment

This article covers the steps I went through to setup my MacBook Pro for Google App Engine (GAE) development. I am using the Python runtime in GAE so the focus here is on a Python development environment.

Python

Setting Python 2.5 as Default

My MacBook Pro is running Snow Leopard. I am planning to host my projects on Google App Engine and it requires Python 2.5. Snow Leopard ships with Python 2.6 as the default. You can switch to Python 2.5 using a few simple commands, as follows:

$ defaults write com.apple.versioner.python Version 2.5
$ sudo defaults write /Library/Preferences/com.apple.versioner.python Version 2.5

After issuing these commands you should logout and login, launch a Terminal window and issue the command

$ python --version

It should report Python 2.5.4 as the result. If it still says Python 2.6.1 then your change did not take effect. To troubleshoot the problem start with man python. It includes information on how to switch the default version of Python on your system.

Additional Python Modules

Google App Engine expects that the ssl module is installed. This is so it can verify the identity of the GAE servers when trying to deploy your projects. Install it like this:

$ curl http://pypi.python.org/packages/source/s/ssl/ssl-1.15.tar.gz --output ssl-1.15.tar.gz
$ tar xvf ssl-1.15.tar.gz
$ cd ssl-1.15
$ sudo python setup.py install

If you want to use the GAE image manipulation classes while running on the local development server you will need to install PIL using the following command.

$ sudo easy_install pil

The following will be necessary for building some other python libraries later in the process.

$ sudo easy_install docutils

The following modules are necessary if you choose to install IPython (see next section). If you are planning on skipping the IPython installation these can be skipped as well.

$ sudo easy_install readline
$ sudo easy_install nose
$ sudo easy_install pexpect

IPython

The IPython interactive interpreter is a good addition to your Python development environment. It does not come pre-installed on Snow Leopard. You can download the latest stable version using this command:

$ curl http://ipython.scipy.org/dist/0.10/ipython-0.10.tar.gz --output ipython-0.10.tar.gz
$ tar -xzf ipython-0.10.tar.gz
$ cd ipython
$ sudo python setup.py install

Google App Engine SDK

The Google App Engine SDK for Python is available at http://code.google.com/appengine/downloads.html. As of this writing you can use the following command to grab the latest version:

$ curl http://googleappengine.googlecode.com/files/GoogleAppEngineLauncher-1.3.7.dmg --output GoogleAppEngineLauncher-1.3.7.dmg

Once you download the dmg file open it in Finder and run the installer. It will place all of the necessary files on your machine. Once complete locate the GoogleAppEngineLauncher.app icon in Finder and double-click on it. This application provides a nice UI for managing your GAE projects.

Source Code Management Tools

Git

I am planning on managing the source code for my projects with git and will store my master repositories on http://github.com. Apple does not include a copy of git on the machine by default. An installer is available at http://help.github.com/mac-git-installation/. While you are at it also create an account on github if you don’t already have one. It is useful for social coding in the wider open-source community.

Mercurial

Some of the Django open source software I plan on using is maintained using a distributed source control management tool called Mercurial. An installer for this is available at http://mercurial.selenic.com. Download and install the software.

$ curl http://mercurial.selenic.com/release/mercurial-1.6.3.tar.gz --output mercurial-1.6.3.tar.gz
$ tar xvf mercurial-1.6.3.tar.gz
$ cd mercurial-1.6.3
$ make PREFIX=/System/Library/Frameworks/Python.framework/Versions/2.5 all
$ sudo make PREFIX=/System/Library/Frameworks/Python.framework/Versions/2.5 install
$ hg version

Django-nonrel

I plan on implementing my web applications on top of the Django framework. Some modifications are required in order for this framework to run properly on GAE since Google uses Big Table for data storage instead of a relational database. Everything necessary to get Django working in GAE is included as part of the Django-nonrel project. Specific instructions for GAE are available at http://www.allbuttonspressed.com/projects/djangoappengine.

Use the commands listed below to install copies of all the necessary components onto your machine. Everything will be stored in a folder called DjangoStuff under your home directory.

$ mkdir $HOME/DjangoStuff
$ cd $HOME/DjangoStuff
$ hg clone https://bitbucket.org/wkornewald/django-nonrel
$ hg clone https://bitbucket.org/wkornewald/djangoappengine
$ hg clone https://bitbucket.org/wkornewald/djangotoolbox
$ hg clone https://bitbucket.org/wkornewald/django-dbindexer
$ hg clone https://bitbucket.org/wkornewald/django-testapp

Now, pick another folder where you want to setup a practice application. I am calling mine cs-practice since this is also the name of my Google App Engine application.

Use the following commands to configure the practice application for Django-nonrel development.

$ mkdir $HOME/cs-practice
$ cd $HOME/cs-practice
$ ln -s $HOME/DjangoStuff/django-nonrel/django django
$ ln -s $HOME/DjangoStuff/djangoappengine djangoappengine
$ ln -s $HOME/DjangoStuff/djangotoolbox/djangotoolbox djangotoolbox
$ ln -s $HOME/DjangoStuff/django-dbindexer/dbindexer dbindexer
$ cp -r $HOME/DjangoStuff/django-testapp/* .

Once you have the practice folder setup you need to edit the app.yaml file and change the application name to reflect the Google App Engine application name you selected when registering on http://appengine.google.com.

Attending iOSDevCamp 2010 – Building Meet4Drinks

iosdevcamp2010.png
I am attending the yearly iOSDevCamp event this weekend in SanJose, CA. This is a great event where iPhone/iPad software developers and UI/UX designers come together for a weekend of coding and exploration of ideas around how to use iOS devices. The event organizers hold something called a Hackathon where attendees form ad-hoc teams around shared application ideas and spend two full days designing and coding like crazy to build something cool. Everyone has a great time and meets like-minded folks in the developer community.

Earlier this year, in April the event organizers held a special iPadDevCamp. That was my first exposure to this great event format. You can read more about that experience over on the Powered By AMP blog. For that event I was on a team with some co-workers from Auctiva. We built a prototype of an e-commerce sales management tool for AMP sellers.

This time I’m attending solo, without a cadre of other Auctiva designers and developers. I want to explore developing location-aware applications for the iPhone and put together a basic idea for an app. It is called Meet4Drinks, and you can read more about it at http://www.meet4drinks.net.

If it sounds like something you would enjoy, it’s not too late to register today. The event starts tomorrow (Friday) evening and goes through Sunday evening. Visit http://www.iosdevcamp.org to register.

Look for updates on Meet4Drinks next week, once my head is back above water after the event. Hope to see you there.