Francisco Soto Ramblings about code, life and stuff.

Installing a Ruby development environment in MacOS X
Jun 02, 2011

The goal of this post is to show how I do set up my Ruby development environment under MacOS X (10.6.7 at the time of this writing), I am writing it down so I do not forget and because probably someone else could benefit from it. Also, keep in mind that this can probably work on other *nix flavors out there (like linux) without much change.

I originally used Macports to install ruby, but in the end this will cause pain when trying to use different versions of Ruby and their respective gemsets.

OK, the culprit of the problem is having different versions of Ruby to work with, for several reasons this is something you probably want, for example, RoR versions previous to 2.3 run only on Ruby 1.8.*, but RoR 3.* runs only on Ruby 1.9.*, there may be other reasons, but this is why I got into this dilemma.

First of all, you may want to get rid of the version of ruby you installed by any package system you may be using, in my case Macports so I have to do :

sudo port uninstall ruby

After that, we are back to system’s old ruby (1.8.7 patch 174 in my system), what we want to do now is install the Ruby Version Manager, rvm is a nice piece of software that manages the chore of having multiple versions of ruby. Quoting from their website: “RVM is a command line tool which allows us to easily install, manage and work with multiple ruby environments from interpreters to sets of gems.”

To install rvm for development (local to your user account, if you want to install it system-wide go check their website) you have to run the following commands on your favorite terminal application. You have to have git installed for it to work :

bash < <(curl -s https://rvm.beginrescueend.com/install/rvm)

echo '[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm" # Load RVM function' >> ~/.profile

source .profile

type rvm | head -1

Please note that .profile is my particular bash configuration script, yours may be .bash_profile or .bashrc, etc., so check that out first.

If after that last command you get a line saying that rvm is a function, you are all set, if you had any troubles then you will have a lot of fun solving them :-)
Anyway, if you had success you now have a working installation of rvm in your user account, so what we want to do next is install ruby! Let’s do that installing 1.9.2 initially, run the following:

rvm install 1.9.2

ruby --version

rvm use 1.9.2 --default

ruby --version

This will install ruby-1.9.2 and use it as a default instead of the system wide, now you can start installing your favorite gems and start coding away:

gem install rails
gem install jekyll
gem install jeweler
...

Now you can install also another version of ruby and switch between them like this :

rvm install 1.8.7

rvm use 1.8.7

ruby --version

gem list

If you do not use the —default switch when running rvm use then the change is local to that session, it will revert to whatever you set as default. If you see, your gem list is empty because you have not installed gems to that version. That’s beautiful. There are ways to manage different sets of gems for the same version of ruby with rvm but I haven’t used this feature yet so I have nothing to say about it.

In the end, if you want to get rid of everything you just have to run

rvm implode

and it will erase rvm, all the versions of ruby you installed with it, their source code, etc., you may need to do some other cleanup, like deleting .rvmrc and removing the line you added to your .profile, but both of these are harmless if you do not do anything about them.

So that’s it. Have fun.

Go up.


comments powered by Disqus