Installing Rails 3 on OS X 10.8

Installing rails

We are not going to say that the OS X system has changed drastically, but certainly installing rails on Mountain Lion has a few speed bumps as apposed to older OS X versions. The majority of documentation for this process still remains on forums and posts and so we at Elephant Head Software thought it was time to bring everyone else up to speed since even upgrades have issues with new rails projects.

The major shift in Apple mentality has come forth with the way that Apple deals with Xcode. You are probably wondering at this point what this has to do with Rails, but stick with the line of thought for a moment and you will understand. With Xcode 4.3 and up, Xcode now lives in the Applicaitons directory, and all of the developer tools and command line tools live there as well. This allows developers to download experimental versions of Xcode which may have different versions of tools or even completely different compilers and allowing them to switch back and forth. They do this so that you can hop between beta versions of iOS and OS X which are not yet supported (and typically will not support older SDKs or and thus your apps may not install on anything other than the beta OS) and the official versions which gets you onto the app store. This way you can install your iOS 6 beta Xcode 4.5 test your code on iOS 6, switch your Xcode back to 4.4 and get completed code up onto the store and etc...

In order to tell your command line what you are up to, you have to use the tool xcode-select. The command is fairly easy to use and you have a few options such as --print-path, which gives you the current location of the Xcode version you have selected. Currently, I am pointed at "/Applications/Xcode45-DP3.app/Contents/Developer" -- which stylistically I am not very happy with. Why should we have to point within the app directory -- why not just point at the .app bundle and have it do the right thing? But alas, its not open source so we have to live with what we are given.

The real trick, you will find, is that you can not run any of the tools on command line. Try it -- svn, gcc, git, all will provide command not found. Thats the next part, to ensure you are running the correct "version," you should now do an xcrun . That will find the location of the Xcode you are using and then pull out the right command. Not great for installing rails where you may have to compile a new version of ruby or something similar.

The solution was not so obvious unless you are an avid Apple programmer and know the system inside out. What needs to happen is you need to mosey on down to http://developers.apple.com and download the "Command Line Tools" for the version of Xcode you are using. That dmg is not featured on the main page so you will have to find hte link for "All Downloads" and click in and hunt it down in the long list. However, once you do and install it, you will find that your issues with running things on command line have magically disappeared!

You are not done yet. The first step we recommend is installing RVM so that you can have a newer version of rails without affecting the OS environment. https://rvm.io/rvm/install/ talks about installing RVM. After you have RVM installed, the next road bump you will find is that with Xcode 4.4, we now only have an LLVM compiler which means you need to link with clang. To install a version of ruby (our flavor was 1.9.2) you need to do:

rvm install 1.9.2 --with-gcc=clang

Without the flag at the end, rvm will complain. Now you are almost there. Simply use the version of ruby you&ve installed

ruby use 1.9.2

and now you may have to install rails depending on how you installed rvm

gem install rails

After that you are set. If you have upgraded to OS X 10.8, you may have a funny environment. Almost all your problems are solved by downloading the command line tools.

Happy rails programming.