Skip to content

Instantly share code, notes, and snippets.

@Lankenau
Forked from raghubetina/installing_rails.md
Last active August 29, 2015 14:20
Show Gist options
  • Select an option

  • Save Lankenau/47eade62cef5f88b7a4d to your computer and use it in GitHub Desktop.

Select an option

Save Lankenau/47eade62cef5f88b7a4d to your computer and use it in GitHub Desktop.

Installing Ruby and Rails

Ruby is a wonderfully simple language, and Rails is an astonishingly powerful framework. Unfortunately, installing them can sometimes be the hardest part of learning to code.

In this guide I will lay out the least error-prone method of installing that we've found. Hopefully you will have no issues and it will be smooth sailing.

In case you do run into an error, first try restarting your computer and then re-try the last step that you got stuck on. If that doesn't work, we'll fix it together.

If you can't install Ruby on your laptop for some reason (for example, it belongs to your employer and you are not allowed to install things), skip to here.

If you have a Windows machine, skip to here.

If you have a Mac running OS X 10.9 or above, skip to here. (To check your OS X version,  menu → About This Mac)

If you have a Mac running OS X 10.8 or below, skip to here.

Windows

Installation is one area where Windows users have it easier than Mac users. All you have to do is download and run one file from RailsInstaller.org (scroll down and find the green Windows Ruby 2.1 button).

This will install everything we need and more. When it asks where to install things, accepting the default option is always safest.

That should be it! If you run into an error during the install, restart your computer and then double-click the installer again. It should complete successfully this time.

To test your installation, find the RailsInstaller folder in your start menu/applications. Inside it, launch the "Command Prompt with Ruby and Rails". (From now on, whenever I say "bring up your terminal", this is what I mean -- launch Command Prompt with Ruby and Rails.)

A black window should pop up. Type in ruby -v and hit return; it should say something like

ruby 2.1.5pXX

Also, run the command rails -v and you should see something like

Rails 4.1.0

or above. You're all set.

Mac

OS X 10.9 and above

Open your Terminal app inside the Utilities folder (the best way is through Spotlight; click the magnifying glass in the top-right corner, or even better, Cmd-Space) and start typing "ter...". Terminal should appear in the results. Hit "Return" to launch.

A window should pop up with a blinking cursor. Terminal is a text-only interface; you can't use your mouse at all. Use the left and right arrows and Backspace to correct errors.

At the cursor, type

xcode-select --install

and hit return. You should get a popup that says you must install developer tools. Click the "Install" button on the far right.

Next, copy and paste this command:

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

It will download and install Homebrew, a package manager. If it asks you to type in your login password, go ahead and do it. It won't look like anything is happening when you type, but it is.

Next, copy and paste:

\curl -L https://get.rvm.io | bash -s stable --ruby

(the leading slash is not a typo, you must include it).

This step might take a while; it will download and install the latest version of Ruby. At some point it might ask you for your password; type the password that you log in to your Mac with (if you don't have one, you may have to temporarily add one and then re-run this command). When you type your password, it will look like nothing is happening, but rest assured -- it is. Type carefully and hit return when done.

Once it is done and returns you to the blinking cursor, Quit Terminal and then restart it. Then:

gem install rails --no-ri --no-rdoc

This will install Rails.

Note: Some students are reporting an error at this step which says something like dyld: Library not loaded.... If you experience this, then run the following:

rvm reinstall 2.2.1 --disable-binary

After that completes, you can redo

gem install rails --no-ri --no-rdoc

And it should work without problems.

You should be all set now; to confirm, do

ruby -v

You should see something like ruby 2.2.1pXX. Do

rails -v

You should see something like Rails 4.2.1.

Let me know if you run into any issues!

OS X 10.6, 10.7, 10.8 (NOT 10.9 or above)

Visit RailsInstaller.org and download the package for your particular OS version -- there's one for 10.7 & 10.8, and a different one for 10.6.

Download and run it. This will install everything we need and more. When it asks where to install things, accepting the default option is always safest.

That should be it! If you run into an error during the install, restart your computer and then double-click the installer again. It should complete successfully this time.

To test your installation, open your Terminal app inside the Utilities folder (the best way is through Spotlight; click the magnifying glass in the top-right corner, or even better, Cmd-Space) and start typing "ter...". Terminal should appear in the results. Hit "Return" to launch.

A window should pop up with a blinking cursor. Terminal is a text-only interface; you can't use your mouse at all. Use the left and right arrows and Backspace to correct errors.

At the cursor, type ruby -v and hit return; it should say something like

ruby 1.9.3p195 (2013-05-14)

We're going to upgrade your Ruby. Enter the command

 rvm install 2.2.1

This might take a while, but when it's done, enter

rvm use 2.2.1 --default

Then Quit the Terminal app and start it up again. Type ruby -v and you should see something like

ruby 2.2.1pXX

One last thing: to get the latest and greatest version of rails, run the following command:

gem update rails --no-ri --no-rdoc

This might take a while, but after it's done and returns you to the blinking cursor, you should be able to run the command rails -v and see something like

Rails 4.2.1

You're all set.

Cloud Development Box: Nitrous.io

If at all possible, I suggest installing Ruby on your own computer so that there is one less layer of abstraction between you and what is going on with your application. However, if for some reason you can't, there's a relatively new option that we can try: a "cloud" development box with Nitrous.io.

What that means: Nitrous provides you with a computer that already has Ruby and Rails installed. The computer they provide is located somewhere in California. You use the computer through your browser. Nitrous provides a text editor to write code with, and a command line to run your apps from, all through the browser.

Pros:

  • We don't have to worry about installing Ruby or Rails.
  • Our apps are immediately live on the internet as we write them with no need to use a separate hosting service.

Cons:

  • We don't get to use Sublime; we have to use their in-browser editor instead.
  • We don't get to use the GitHub Desktop app; we have to learn some command-line commands instead.

Here are the commands you need to know in order to replace the GitHub Desktop app:

First, you need to know your Command Line Basics to navigate around, since there is no Finder/Windows Explorer.

Once you have navigated to the folder you want to clone to,

  • To clone:

     git clone https://github.com/YOUR_ACCOUNT_NAME/REPO_NAME
    
  • To sync:

     git add -A
     git commit -m "YOUR MESSAGE HERE"
     git push
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment