Environment & Source Control
Setting up your environment can be difficult when you’re first starting with Ruby. We want to get the following installed:
- Ruby 2.1
- A text editor
The setup instructions are broken down by platform: Mac, Linux, and Windows.
Mac OS is the most popular platform for Ruby and Rails developers. These instructions assume you’re on the latest version of MacOS, 10.9. If you’re using an older version, refer to these additional notes.
XCode & Command Line Tools
XCode is a huge suite of development tools published by Apple. You’ll want to install it before attempting to install anything else.
- Install XCode from the Apple App Store
- Open the application after installing and agree to the SLA terms
xcode-select --install, enter your user password
You should be good to go!
Homebrew is a package management system that makes it easy to install hundreds of open source projects and compile them from source for maximum performance on your machine.
Open the Terminal (You can search for it using Spotlight, or find it in
Applications > Utilities > Terminal), then run the homebrew installation script:
It will ask you for your password. This is the password to log in to your account on the computer.
When it has completed the installation run
brew doctor and it should tell you that everything is fine:
Git is the version control system of choice in the Ruby community. XCode installed an older version of Git for you, but let’s update it.
RVM allows you to install and maintain multiple versions of Ruby. More information about Ruby Version Mananger (RVM) can be found at http://rvm.io.
Similar to Homebrew, RVM provides a script to get everything installed. Run this in your Terminal:
Loading / Post-Install
Look for the line in the output from the RVM installation that starts with
Copy the command inside of the backticks (don’t include the backticks), paste it into your terminal window, and hit enter.
Check if it got installed correctly by checking the version.
It should give you a version number rather than an error message.
We’re going to install Ruby 2.1. If you need another version it’ll be same procedure, just replace "2.1" in the instructions with whichever version you want.
To list all of the possible Ruby versions that you can install, use the command:
We recommend getting the latest stable version of Ruby, which is version 2.1. Install it with:
There are several additional libraries that gems will often rely on. RVM makes installing those easy, too. Run this command:
It’ll figure out what needs to be installed and install it.
Setting the Default Version
You can tell rvm which Ruby version you want to use by default:
If you don’t already have a favorite text editor, we recommend using Sublime Text 2.
Postgres is the database of choice for most Rails projects.
Homebrew has Postgres for you. From your terminal:
Follow the notes that Homebrew prints out to setup Postgres to automatically start when your machine turns on.
Creating the Database Instance & Adding a User
Once installed, we need to create the database instance. We’ll need to use
sudo which will cause the first instruction to ask for your MacOS user password. From your terminal:
$ $ $ $ $
Respond "Y" to
Shall the new role be a superuser? Now Postgres should be good to go!
Verifying Install and Permissions
Let’s create a database and connect to it:
You should see the following (note: use
\q to exit):
If you got that, then Postgres is good to go.
If Mac OS isn’t a possibility, then your next best bet is Linux. Among distributions, Ubuntu has the best support for Ruby and Rails development.
Check out our tutorial for setting up a Vagrant/Linux virtual machine. Just skip the bits about Vagrant, all the other Linux-centric setup is the same.
Getting started on the Windows platform is actually very easy. Engine Yard (http://engineyard.com) has put together the RailsInstaller (http://railsinstaller.org/), a single package installer with all the tools you need to get working. Make sure that, during the setup, you check the box to configure your environment variables. You can stop after step 2, once you’ve entered your email and name in the DOS prompt.
Beyond initial setup, though, there is going to be pain. As you add in more Gems and other dependencies you’ll find that many of them utilize native extensions, code written in C for better performance. Unless the authors have put energy into being cross-platform, you’ll run into issues.
Instead, we recommend using VirtualBox and Vagrant to run a Linux virtual machine within your Windows host operating system.
Check out our Vagrant Setup tutorial for a full walk-through.