Introduction

Installing Ruby on Rails in Yosemite is easy, but there are a couple of steps. This article will walk you through those steps. Let's get started.

Operating System Mac OS X 10.10.x Yosemite
Ruby Version 2.2+
Rails Version 4.2+
Last Update 2/15/2015 7:01pm EST

Step 1: Install Homebrew

Homebrew is a popular platform that is used to compile and install open source applications. We will use Homebrew to install a number of different applications. To install Homebrew, open a Terminal (Choose Utilities from the Go menu, then find the Terminal Application in the list.) and copy/paste the following command and press enter.

Terminal Commands:

ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

A software installation window should come up, wait for it to complete, then switch back to the Terminal window and press enter. You'll then be prompted to enter your password, do so and press enter. Homebrew should now be installed. Next run the following command to ensure that Homebrew is properly installed.

Terminal Commands:

brew doctor

You should receive a message saying that Your system is ready to brew. This indicates that Homebrew is set up properly and ready to use..

Step 2: Install rbenv and ruby-build

Now that we have Homebrew installed, we can install rbenv and ruby-build. rbenv is an awesome tool that is used to manage different Ruby versions and ruby-build is a plugin that allows you to install specific ruby versions right from the command line. To install them both run the following command.

Terminal Commands:

brew install rbenv ruby-build

Step 3: Installing Ruby

Now we are ready to install Ruby. First, run the following command to get a list of all of the Ruby versions. You can optionally skip this step and just install 2.2.0, but depending on how old this article is, 2.2.0 may eventually be out of date.

Terminal Commands:

rbenv install -l

You should see a large list of ruby versions, scroll up until you see versions that start with a number. The highest number corresponds to the latest version. As of this writing there is 2.2.0 and 2.3.0-dev. We want 2.2.0 because it's stable. Now run the following command to install 2.2.0.

Terminal Commands:

rbenv install 2.2.0

After some time the new version of Ruby will be installed. Now run the following command to set it as the default Ruby.

Terminal Commands:

rbenv global 2.2.0

Step 4: Installing a Database.

Next we need to install a database server. I've included instructions for both MySQL as well as PostgreSQL below. If you unsure which to choose, chose PostgreSQL. It tends to be the more popular option in the Ruby on Rails world. You can always come back and install MySQL later if needed.

Installing PostgreSQL

You can skip this section if you are installing MySQL. To install PostgreSQL, run the following command.

Terminal Commands:

brew install postgresql

After a bit of time, PostgreSQL will be installed. Next run the following command to add it to your startup.

Terminal Commands:

ln -sfv /usr/local/opt/postgresql/*.plist ~/Library/LaunchAgents

Next run the following command to start PostgreSQL.

Terminal Commands:

launchctl load ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist

By default, the a user is created with your OS X username and no password. You can type whoami to get this username.

Installing MySQL

You can skip this section if you are using PostgreSQL. To install MySQL, run the following command.

Terminal Commands:

brew install mysql

After a bit of time MySQL will be installed, next run the following command to have it run on login.

Terminal Commands:

ln -sfv /usr/local/opt/mysql/*.plist ~/Library/LaunchAgents

Now run the following command to start MySQL.

Terminal Commands:

launchctl load ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist

Now we need to finish the setup of the MySQL server by setting a root password and removing anonymous users, etc. Run the following command to do this.

Terminal Commands:

mysql_secure_installation
  1. First, you will be prompted to enter the root password. The default root password is blank, so just push enter.
  2. You will then be prompted to set a root password. Press y, push enter, and set the root password.
  3. Next you will be prompted to remove anonymous users. Press y and push enter.
  4. Next you will be prompted to disallow remote root login. It is recommended that you do this unless you have need to access your database remotely using root. Press y unless you wish to allow remote root access and push enter.
  5. For the next 2 prompts (test database and reload privileges) press enter.

Great! Now MySQL is installed and ready to use.

Step 5: Set Up Git

Next we need to set up git. First, set your name and email with the following commands. Replace 'Your Name' and [email protected]' with your own name and email.

Terminal Commands:

git config --global user.name “Your Name“
git config --global user.email [email protected]"

Next we need to generate an ssh key. Run the following command to generate an ssh key.

Terminal Commands:

ssh-keygen

If you want to use a passphrase, enter one when prompted, otherwise just press enter. After the key is generated you can then run the following command to view your public key.

Terminal Commands:

cat ~/.ssh/id_rsa.pub

From there you can add it to Github, Bitbucket, or some other service.

Step 6: Install Rails

Installing Rails is simply a matter of running the following commands

Terminal Commands:

gem install rails

This will install the latest stable version of Rails.

Final Words

If creating a new rails app, make sure to specify the database engine with the -d flag.

Terminal Commands for For MySQL Based Apps:

rails new myapp -d mysql
Terminal Commands for For PostgreSQL Based Apps:

rails new myapp -d postgresql

That's it, thanks for reading!

Resources