Installing a Ruby dev environment on OSX
I recently bought a new Macbook Air 13" (which is übercool btw), and took my time to set up my development environment properly. Here’s a recipe for setting up everything you need on a fresh OSX install, with some nice-to-have applications as well.
RVM
Although OSX comes with Ruby by default, you’re probably going to need different versions of Ruby sooner or later. RVM: Ruby Version Manager is a nice set of scripts, that enables you to switch between different versions of Ruby, including JRuby, REE, MRI and YARV. The basic installation is pretty straight forward, just run the following script and follow the post-installation instructions to run the required scripts upon opening a new bash shell.
bash < <( curl http://rvm.beginrescueend.com/releases/rvm-install-head )
After you’ve installed RVM, and loaded it, I recommend installing YARV (1.9.2) and set that as your default Ruby:
rvm install 1.9.2-head && rvm use 1.9.2 --default
Homebrew
Homebrew is a simple, yet powerful, package manager for OSX. It’ll allow you to easily install and manage different UNIX tools, pretty much like APT on Ubuntu. Installing Homebrew is pretty straight forward, except for the last step where you have to get the Apple developer tool, XCode.
Run this script to get Homebrew:
ruby -e "$(curl -fsSL https://gist.github.com/raw/323731/install_homebrew.rb)"
Then go download XCode from Apple. You’ll have to make an account, and download quite a large installation file. Uncheck everything except the base during the installation, unless you want the libs for iOS development and such.
Git
Git is a widely used VCS (Version Control System) amongst Rubyists, and you’ll need that for working with code on Github, the most popular host for open source Ruby projects. Since we’ve installed Homebrew, getting Git up and running on your machine is pretty easy:
brew install git
To configure Git for all your projects, you can add rules into ~/.gitconfig, this is how my config file looks like:
[user]
name = Lars
email = ovelar@gmail.com
[core]
excludesfile = /Users/lars/.config/global-gitignore
The last line references a global gitignore file, where we’ll add files we know that we never want to check into our repositories. A basic gitignore file on OSX should atleast contain .DS\_Store, and you’ll probably add *.log as well.
MySQL
Installing MySQL with Homebrew is pretty straight forward as well:
brew install mysql
mysql_install_db
Post installation you will see a set of commands you can run to make MySQL start when you log in to your computer.
MongoDB
For my NoSQL adventures, I use MongoDB. For my production setup, I use a hosted service from MongoHQ, but I would recommend setting up a local instance for development and running tests. Installing MongoDB with Homebrew is also as easy as MySQL:
brew install mongodb
You’ll get the same output post installation, with two lines you have to run in order to have your MongoDB instance start up on login.
Editor
When it comes to editors, this is a matter of personal taste and a religious topic amongst programmers. When I got my first mac a year ago, I started using TextMate, which has been kind to me. Lately, I’ve started using MacVim, mostly because I wanted to have the same environment on my mac and ubuntu machine. Others might prefer emacs or even KomodoEdit. Anyways, you can install MacVim easily with Homebrew: brew install macvim
Nice to have utilitites
- Visor allows you to have a roll-down terminal window on all your spaces.
- Growl gives you pop-up notifications on your desktop, that can be utilized by things like AutoTest
- GitX is a nice GUI for basic git stuff.
- HyperDock enhances the default window manager in OSX
- GithubNotifier gives you notifications (via growl) on new commits on you Github projects
Also, having a cool bash prompt is a must, this is what I use for my prompt which shows current ruby version (from RVM) and branch name if you’re in a Git repo:
PS1='\[\033[0;32m\]\u@\h\[\033[1;30m\] ($(~/.rvm/bin/rvm-prompt i v g))\[\033[0m\]\[\033[0m\] \[\033[1;33m\]\w\[\033[0m\]\[\033[1;37m\]$(__git_ps1 "[%s]")$ '
Happy hacking, and good luck with your new Mac :)