Why Rails
Rails is a web-application framework that includes everything needed to create database-backed web applications according to the Model-View-Control pattern.
This guide does not only involve installing ruby sucessfully in Lion. It also explains how to serve a whole project on the cloud easily.
Although all this might sound a little bit tough, this tutorial can be also followed as a step-by-step guide.
These are the instructions to install Ruby and Rails in your Lion system.
Steps
- Install XCode (it includes git and the rest of tool for compiling Ruby sources)
- Install HomeBrew
- Install Ruby through RVM
- Create Rails App
- Deployment to Heroku
Install HomeBrew
Homebrew makes the installation of UNIX tools (or other occasional utilities that Apple didn’t include with OS X) easier than MacPorts or Fink.
Its installation is simple and avoids lots of manual and noisy installations of needed tools during development, e.g.: postgresql, imagemagick, etc):
1 2 | |
Install RVM
RVM is a tool that makes it super easy to install, manage and work with multiple versions of Ruby, interpreters and sets of Gems.
Uh. And what the heck is “Gems”? Gems is a package manager for the Ruby programming language that provides a standard format for distributing Ruby programs and libraries (yep!, as Python has eggs, as node.js uses npm, or as PHP comes with PEAR).
The gem command is used to build, upload, download, and install Gem packages.
With RVM you can have 1.8.7 and 1.9.2 live together without any issues. You can even swap back and forth from 1.8.7 to 1.9.2 as you see fit.
To install RVM in your system, run this:
1
| |
Now it’s time for echoing to .bash_profile our new environment and installing ruby:
1 2 3 4 5 | |
From now on, just refer RVM to the version of ruby you want to run:
1 2 3 4 5 | |
Probably, this would be also a good moment to install some extra tools through brew:
1
| |
This remarkable package manager is written in Ruby too, which means you cam make your own homebrew formula (here you have a hint on how to) in case you need a custom source for a specific package.
Create your Rails App
Let’s create an empty Rails project to play with. Just run in your terminal
1 2 3 4 | |
Now you should see something at http://localhost:3000!
Deploying to Heroku
If you don’t have an account yet, here you have some reasons to register then:
- It’s free in case you don’t need many resources
- It’s suitable for small projects and demos. Check its features.
Get to your app path and run:
1 2 3 4 | |
Git uses SSH as its secure transport protocol. And Heroku uses Git, so you’ll need to generate a public SSH key and upload it to Heroku. Some details are described in this Heroku article.
Time to deploy our app:
1 2 3 | |