Which OS for Rails?

August 21st, 2014

Why write about this topic? Isn’t the answer obvious?

Maybe for many.

However, thanks in large part to the initiatives of reInteractive and Ruby Australia, there is an increasing number of Australian newcomers to Rails. Many are predominantly familiar with Windows when it comes to the operating system on their own machine.

The Background to the Question

Who prompted this post? It was Rosie Williams when she posed the following question on the Rails Oceania mailing list:

I’ve begun learning RoR but want to know what operating system to continue with that is most in demand in the market? To date I’ve done most of my development on Windows (which dual boots to Linux which I’ve not really used). I am considering buying a new Mac for development but wondering whether I ought to be doing my RoR on Linux? Or does it not really matter?

Thanks to the generosity of the community, Rosie has received many helpful suggestions.

The Short Answer

Most Rails developers use OS X or Linux. The majority use OS X.

Assuming OS X, What Next?

Given that most Rails developers use OS X, I am one of them and Rosie now has a new Macbook Air, I will continue this post on the assumption that OS X has been chosen. What will the developer want to focus on next when preparing to start their first Rails application on OS X?

The Command Line

I was going to start with Homebrew but I think there’s an important step before that. Often newcomers to Rails who are used to Windows do not have familiarity with using the command line.

I think it is important to stress that if you want to dive into web development with Ruby on Rails in a serious way, you absolutely need to develop a sufficient level of comfort with using the command line. In OS X, that can be using bash via Terminal. Personally, I prefer iTerm2 to Terminal. And many developers prefer zsh to bash.

In any case, the important thing is this: embrace the command line. You are going to need to depend upon it!

Xcode Command Line Tools

As keen as I am to mention that you’ll need Homebrew, before then you are going to need to install Apple’s Xcode command line tools. Over time Apple has changed the method for installing these tool tools. At the time of writing, you need to register as an Apple developer and then sign into the Apple developer downloads site so that you can download and install the command line tools.

Update: An easier method of installing Command Line Tools, namely running xcode-select --install from the command line, has been known to work. It’s worth trying this first before resorting to registering and downloading as described above.

Homebrew

OK, next up is Homebrew, the package manager that is simply indispensible to developers using OS X. Throughout your journey as a Rails developer using a Mac, there will be many occasions when you will need to install software on which your application depends. It might be PostgreSQL. Or it may be imagemagick. Or git. In almost every case you will simply be able to run brew install <package-name> from the command line and Bob’s your uncle.

Notice I mentioned using the command line! Anyway, install Homebrew and let it do your bidding. And once you have, get into the habit of using brew update, brew outdated, brew upgrade, brew cleanup and brew doctor to keep your Homebrew packages in good shape.

Ruby

Now, obviously a Ruby on Rails developer needs Ruby on their machine. And, OS X does indeed come with Ruby installed. However, it is almost certainly an older version than you will need. At the time of writing, the latest version of Ruby is 2.1.2.

To install and manage Ruby versions, unless you are going to compile from source manually, you have three choices:

These are listed in chronological order. I have happily used rbenv for some time, having discarded RVM. Many Ruby developers whom I respect recommend chruby. Pick one and install the latest version of Ruby.

Update: If you would like to know more about each of these Ruby version managers, I recommend you listen to Episode 169 of the Ruby Rogues podcast.

RubyGems

Fortunately, RubyGems, the default package manager for Ruby, is part of the Ruby standard library, as of version 1.9. So, once you have installed Ruby, you will have RubyGems at your disposal to install software such as Ruby on Rails.

Rails

Opening your trusty command line (e.g. Terminal), run the command gem install rails, wait for a while, and Rails should be installed. Type rails -v to confirm the version that has just been installed for you, courtesy of RubyGems.

Other software

Having got this far, you should be ready to start experimenting with Rails development. However, before long you will likely need to install some other software that your application needs.

If it is software in the form of a RubyGem, the accepted practice these days is to add the gem to your application’s Gemfile and use bundler to install and update it. There are all sorts of gems available. The Ruby Toolbox is a good place to explore your options.

If the software you need is not built with Ruby, the chances are that you will be able to install it using Homebrew. For example you are definitely going to need git. At the command line, enter brew install git and you should be set.

Other considerations

Naturally, when dealing with computers, it is not uncommon to be presented with a surprise when you may have expected something to “just work”. For example, sometimes on UNIX-based systems, commands fail due to permissions problems and the error message doesn’t always make it clear that this is the source of the problem. In this case, get to know UNIX permissions and chmod.

Something else that I think is worth mentioning is the awesome combination of Dash and Alfred for quickly looking up API documentation.

And, of course, remember that there are always people online who are willing to help.

In Conclusion

Whilst there are many other aspects that could be covered within the topic of “what to do next having chosen OS X for Rails development”, I think I’ll leave it there as far as this post goes. And, Rosie Williams, if you’re reading, I wish you all the best with developing Rails applications on your new Macbook Air and I hope that I have been of some help.

Update: Credit where credit is due. Leonard Garvey has reminded me about his excellent Rails Install Fest Guide.