Skip to content

Instantly share code, notes, and snippets.

@raghubetina
Last active November 15, 2018 18:34
Show Gist options
  • Save raghubetina/5c74297269e40bc5c7c9 to your computer and use it in GitHub Desktop.
Save raghubetina/5c74297269e40bc5c7c9 to your computer and use it in GitHub Desktop.
Installing Ruby and Rails

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)

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.2 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.2.4pXX

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

Rails 4.2.x

or above. You're all set.

If you see The system cannot find the path specified. when you type rails -v, then please follow these steps to resolve.

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, paste

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. Type carefully -- 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:

rvm install 2.3.1

Then,

rvm use 2.3.1 --default

Then,

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

This will install Rails.

You should be all set now; to confirm, do

ruby -v

You should see something like ruby 2.3.1pXX. Do

rails -v

You should see something like Rails 5.0.x.

Let me know if you run into any issues!

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 Atom; 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