* Updated on 11th of May, 2015, thanks Jamestoher for the update *
Installing Ruby on Rails on a Mac can be a daunting task. From 10.6 to 10.10, I’ve been through all the issues. Starting with mac ports and all kinds of ruby installers. I’m going to explain how to setup the rails environment as easy as possible. We’re going to start with a clean Yosemite install, so we don’t have any conflicts with already installed software.
Step 1. Install Homebrew
Homebrew is a package manager for the Mac. Just like you have apt or yum on linux. It can install all sorts of applications and libraries. Start off with installing Homebrew by issuing the following command:
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
To make sure Homebrew is installed correctly run:
Step 2. Install RVM
RVM stands for Ruby Version Manager. It can manage multiple ruby versions. This is especially handy when you have more than one applications to control. But it’s also handy to isolate ruby and it’s gems. Starting a new app with the latest version of ruby, no problem, while still running your older app simultaneously.
gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3
\curl -sSL https://get.rvm.io | bash -s stable
Reload your bash_profile, so it can initialise RVM.
Run RVM requirements to install basic required packages with Homebrew. Accept the license agreement and install Xcode Tools. After installing the tools continue the rvm requirements installation.
Step 3. Install latest Ruby
Install ruby, ruby-head is the latest version. You can also use 1.9.3 for example or even a ruby version with a different patchlevel. For ease of use we use ruby-head. You can call ‘rvm list known’ for all available rvm environments.
rvm install ruby-head
Optional. Install Git
Git a version control system, which can be used to control your code repository.
brew install git
Optional. Install MySQL
Install MySQL database and the client to connect to it. This used to be a tricky ordeal because the mysql2 gem needed specific locations for the files. Right now it should work out-the-box.
brew install mysql
Optional. Install MongoDB
MongoDB is very well known document database. Only install it when you know you need it. There are many alternatives such as Redis for key-value database.
brew install mongo
sudo mkdir -p /data/db/
mongod # to start
Optional. Install PostgreSQL
Postgres is a more advanced SQL database. I think it’s becoming more default now since MySQL was taken over by Oracle. Decide which one you would want to use. Beginners can better start with MySQL.
brew install postgresql
That’s it after install all these packages you can start a new rails app by running:
rails new your_application_name
Rails shouldn’t be that hard to install anymore. Best of luck!
My working environment
Lastly, here is my Mac working environment. I use all of the applications on a daily basis: