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.
Install XCode
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.
Install MacPorts
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.
Install RVM
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
[html][[ -s $HOME/.rvm/scripts/rvm ]] && source $HOME/.rvm/scripts/rvm[/html]
Let’s try if everything is working with the command “rvm“.
Install Ruby
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“.
Install Rails
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 [email protected]“.
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“.
Install Passenger
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.
Final Test
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.
Conclusion
We obviously thank the always up-to-date complete guide from RobbyOnRails and Mark Turner. Now you’re able to explore new frontiers of web programming with Rails!
Please take a minute to chime in and leave a comment below :)
Author: Marco Lisci
Marco Lisci (Web Design/Dev) and Luisa Scarlata (Creative/Copywriter) design and develop for the web, have creative ideas and write award-winning copy. Visit their website at Bad Shark Communications.
Very good post.Thank you.
Nice Article !!! Thx for sharing your experience. I found another good article at http://www.makeurownrules.com/ruby-on-rails/minify-compress-synch-amazons3-capistrano which is explain about uploading the minified/compressed static content on Amazon S3.
Very good post. Simple, easy to follow, and now I’m tempted to give it a try myself. Thanks again!
I got to the point where I installed ruby 1.9.2 which was successful. But when I executed ‘ruby 1.9.2’ and then ‘ruby -v’ it still pointed to 1.8.7. Anyone have an idea of what went wrong?
Worked for me on snow leopard. I closed and re-opened terminal first.
In the “installing rails” section you say to “rvm use –create [email protected]“. That did not work. Perhaps it’s shorthand, but what did work is “rvm gemset create rails3; rvm use [email protected]”.
Nice instructions though. I’m on day 2 of learning ruby/rails the hard way and this was quite useful.
rvm-install did not work for me, but this did:
bash < <( curl http://rvm.beginrescueend.com/releases/rvm-install-latest )
Thanks for a really useful post.
Similar to Pduey, using “rvm use -create [email protected]” does not work. Using “rvm gemset create rails3; rvm use [email protected]″ also did not work, however using this it did ” rvm 1.9.2; rvm gemset create rails3; rvm use rails3;”
Also, when installing sqlite3-ruby I received this message:
#######################################################
Hello! The sqlite3-ruby gem has changed it’s name to just sqlite3. Rather than
installing `sqlite3-ruby`, you should install `sqlite3`. Please update your
dependencies accordingly.
Thanks from the Ruby sqlite3 team!
<3 <3 <3 <3
#######################################################
Thanks for the tutorial! It's been a learning experience for sure.
Thank you! This was very helpful.
To anyone having problems with “rvm use -create [email protected]″ the problem is there should be two “-“, not one as the example suggests.
This is the correct version of it: “rvm –create [email protected]”
I got it installed. Can anyone tell me how i can configure mysql with this installation ?