Setting up a Rails Development System on Mac OSX Snow Leopard
In this article we’ll follow some easy steps to install and configure properly a Rails Development Environment in Mac OSX Snow Leopard. In our lab test we ran through all the steps in around one hour, considering all download and installing times.
We’ll start installing XCode, the Apple Developer Package. We need it to compile some source packages that we’ll install later. You can install XCode from the original OS X DVD, or you can download it for free from Apple’s website. Since it’s a normal package, you can just click on the package and it will be automatically installed.
Now we need MacPorts. Since some of the following needed packages are command line tools, MacPorts will make easy to compile and install them. You can download the pkg file on the MacPorts site. This is a normal OS X package file too, so by clicking on it the MacPorts system will be installed. Let’s test if MacPorts has been installed correctly with the command “port” in the terminal. If everything is fine we should enter the MacPorts interactive mode.
This is an optional, but very recommended step. We could use the standard Ruby version that comes with OSX, but Ruby Version Manager will allow us to install the latest version and switch between versions, to keep well maintained separated ruby environments. So let’s input in the terminal “sudo gem install rvm“, and then “rvm-install“. Now we have installed RVM, but we need to add to our .profile preference file the following string
[[ -s $HOME/.rvm/scripts/rvm ]] && source $HOME/.rvm/scripts/rvm
Let’s try if everything is working with the command “rvm“.
Now we can install Ruby using RVM and creating an independent environment from our original OS X system. Let’s start by installing the latest version of Ruby with the command “rvm install 1.9.2“. This command, after downloading the files will compile our new shining latest ruby version.
You can test rvm by switching from version 1.9.2 and the system version, with the command “rvm 1.9.2” and “rvm system“.
Now we’re going to create a set of gems in RVM for our Rails 3 system. Let’s launch the command “rvm use –create 1.9.2@rails3“.
The output will be “Using Ruby 1.9.2 with gemset Rails3“, that is clear and easy to understand. So, let’s install Rails and the db gems with the command “gem install sqlite3-ruby” and “gem install rails“.
Since we have Apache on OS X, we can install Passenger to use our already installed web server with Rails. Let’s start by installing the gem with “gem install passenger” and then install the Apache2 module to connect Passenger with “rvmsudo passenger-install-apache2-module“.
Now everything should be in place, we just need to create the passenger configuration file in “/private/etc/apache2/other/passenger.conf“. The first three lines are the code that Passenger installer told us to put into the configuration file. The directory statement simply tells Apache where to look for our projects.
Now everything should be in place, so let’s download the Passenger Preference Pane from FingerTips and let’s test our system.
First, let’s create a test Rails app with the command “rails new testApp” launched in our directory “railsApps“.
Then activate the Apache server with Web Sharing in the Mac Sharing Preferences and add the newly created directory with the Passenger Preference Panel. If you go to the address “testapp.local” in your web browser you should see the standard rails welcome page.
Please take a minute to chime in and leave a comment below :)