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.
If you don’t already have a favorite text editor, we recommend using Atom.
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.
The terminal is a textual interface to your computer.
You can move around folders (called directories) and run programs within it.
For example, when you run
ruby, you are running that program from the terminal.
If this is all new for you, see Terminal and Editor
You can use the existing terminal, or my favourite: iTerm2. To launch the terminal, go to Spotlight and type "Terminal" or "iTerm" and then run it. The following commands expect a terminal.
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, it needs this because it installs its packages in a place that all users of this computer can access.
When it has completed the installation run
brew doctor and it should tell you that everything is fine:
If it says something like "Warning: /usr/bin occurs before /usr/local/bin", then you need to edit a variable called your PATH.
The PATH variable is how your shell finds programs you are trying to run. For example, when we just ran
$ brew doctor, how did it
know where to find the brew program? It looked through a list of directories until it found
brew. The list is stored in the
You can see the list with
$ echo "$PATH", which should print out a long string of directories, delimited by colons.
You can make this more human-friendly by translating colons into newlines like this:
$ echo "$PATH" | tr : "\n".
The program you are trying to run may show up at multiple places in these directories. For example, if you said
which -a git,
it might tell you that there is a git in "/usr/bin/git" and also in "/usr/local/bin/git". Since the shell will execute the first
one that it finds, we need to make sure that the one we want (the homebrew one, in /usr/local/bin) is the one it finds,
which means that "/usr/local/bin" needs to be earlier in the path.
We can place it earlier in the path by editing the configuration file for our shell:
At the top of this file, type
export PATH="/usr/local/bin:$PATH" which will add "/usr/local/bin", homebrew’s install location,
to the beginning of the path.
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:
Postgres is the database of choice for most Rails projects.
Homebrew has Postgres for you. From your terminal:
Set It to Run on Startup
Run the following commands to make it start when you turn on your computer and start right now:
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.