So you want to play with Ruby?


Last week I heard two people complaining about how difficult it is to install Ruby on a Mac and start coding with all our precious gems. They deserve explanations.

Alright let’s have a quick look at that and install our Ruby env with all tools required to code and deploy on Heroku.

Being able to compile

First of all you need GCC aka the compiler. Previously it was packaged along with XCode but it’s not the case anymore. You can get GCC from github. Download it and just unpack it as usual.

New packaging system

If you’re bored of macport or if you don’t know it already try Homebrew. Homebrew is a package installer based on recipes. To install it type:

/usr/bin/ruby -e "$(curl -fsSL https://raw.github.com/gist/323731)"

The script installs Homebrew to /usr/local so that you don’t need sudo when you brew install. It is a careful script, it can be run even if you have stuff installed to /usr/local already. It tells you exactly what it will do before it does it too. And you have to confirm everything it will do before it starts.

The Ruby env

I suggest you to install rbenv, a ruby version manager. RVM was the first and awesome one but heavy to maintain and weirdly plugged into the system. To install rbenv and ruby-install (the rubies installer):

brew update
brew install rbenv
brew install ruby-build

Then to install the last Ruby version and update your system:

rbenv install 1.9.3-p125
rbenv rehash
rbenv global 1.9.3-p125
gem update --system

This will quickly install ruby 1.9.3 patch 125 (the latest one today), define it as the default Ruby version and update your gems. Now add the following lines to your .bash_profile:

export PATH="$HOME/.rbenv/bin:/usr/local/bin:/usr/local/sbin:$PATH"
eval "$(rbenv init -)"

I know that was a lot of manipulation just to install Ruby but now you’ll be able to add any ruby version you want for a specific project or just for the sake of trying it !! Restart your terminal then check your Ruby version:

ruby -v

GIT, THE Version control tool

I have tried CVS, SVN and Git. GIT is  definitely the best Version Control management tool. That’s said. Simple. To install it we’ll use brew:

brew install git

You’re DONE !!

Now you have a working env with as many ruby version as you want, a new (efficient) package manager and git command. To start hacking just git clone an OpenSource project from github like:

git clone git@github.com:vzmind/salesforce-padrino.git

That will create a salesforce-padrino folder and pull into the project code from github. When your modifications are done on that project and you want to deploy that code to Heroku, you’ll have to launch:

heroku create
git push heroku master

The last step clearly deserves more explanations but it’s clearly a different topic (choosing your IDE, creating an Heroku app, using Git).

Tagged , , , , , ,

6 thoughts on “So you want to play with Ruby?

  1. bashirqaasim says:

    Great post on getting started with ROR!

  2. Great work! I especially like video for Dove Men+Care. Nice touch.

  3. Raymond Gao says:

    Don’t forget to add a good IDE to the development…

  4. […] So you want to play with ruby […]

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: