Saturday, March 2, 2013

How to Install Ruby on Rails

I feel like getting Ruby on Rails up and started is kinda difficult, especially for Linux herp-derps like me.  I will start by saying that I kinda suck at Linux, so it took me a while to set up Ruby on Rails.  But eventually I found a procedure that will work!  I'll keep things short and simple, since you probably just want Ruby on Rails up and running ASAP!

We're going to do [pretty much] everything from the terminal.  So one thing to keep in mind is, I'm going to use "yum" since I use Fedora, but if you use Debian, Ubuntu, or Mint, you would use "apt-get" in place of all the times I used "yum".  The easy way to do this is, if one of them didn't work, then try the other!

I read online that all the kool katz these days use this thing called RVM to manage their Ruby versions, so I decided to hop on the bandwagon and do it too (and so should you).

Now, enough talking... open the Terminal and let's get started.  The important stuff will be in red, so you can ignore all of my noobish comments.  Every line that starts with a $ means that you type everything after the $ into the terminal, and every time you you do a "sudo yum install" it will ask for your password (so type that in when prompted) and ask if it's OK to install stuff (so type "y" to confirm).

Step 1:  Update your pre-existing packages

$ sudo yum update

Step 2:  Install curl

$ sudo yum install curl

Step 3:  Install RVM

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

Step 4:  Load RVM

$ source ~/.rvm/scripts/rvm

Step 5:  Install dependencies

$ rvm requirements

That should print out a bunch of crap, but we're only interested in the stuff immediately after "# For ruby:" under "Additional Dependencies."  I don't know if it'll be verbatim when you're reading this, but as of now, that's how it goes.

Copy all of the stuff after "sudo yum ..." until the end of the paragraph and paste it into the current line in the Terminal, and then press [ENTER].  This could possibly take some time.

Step 6:  Install Ruby and set a default version

The current version as of now is 2.0.0, but it might be different, so do a Google search to find out what version we're currently at.

$ rvm install 2.0.0
$ rvm use 2.0.0 --default

This part might take some time... so go play Intergalactic Exterminator while you wait, since that's what I did.

Step 7:  Install RubyGems

$ rvm rubygems current

Step 8:  Install Rails

$ gem install rails

This part also might take some time, so go ahead and beat another few levels in Intergalactic Exterminator.  When you beat the game, the installation should be finished [for a while, probably].

Yay!  You're done.  But you might have run into some errors.  One of the errors I remember that came up was the sqlite3 problem.

Step 9:  Fix Errors (i.e. Google search)

So here's how you fix that particular error (blue text for possibly important):

$ sudo yum install sqlite-devel
$ sudo yum install ruby-devel
$ gem install sqlite3

A good way to check if "rails" is installed/working is typing the following command.  You should get some version number like 3.2 or something.  It might not be the exact same when you're doing it, but it's 3.2 right now for me.

$ rails -v

Now you can use Terminal and navigate to the folder you want to put your first Ruby on Rails program in.  If you don't know what I mean, read up (i.e. do a Google search) on the cd command.  Now you simply type (of course replace "<project-name>" with the name of your project):

$ rails new <project-name>

After that, it's all up to you where you want to go!  I'd say you should look at what a scaffold is since it makes starting up quickly very easy.  Don't forget to cd into your project's folder!

Step 10:  One last thing - Starting RVM automatically with Terminal

Now one thing I found rather frustrating was that whenever I closed terminal, I couldn't use "rails" in Terminal anymore, unless I typed the following command:

$ source $(rvm 2.0.0 do rvm env --path)

Which is really annoying to do every time.  So I did what any rational human would do -- I did a Google search.  Took a little bit, but I was able to scrape enough information to come up with a solution!

$ gedit ~/.bashrc

A text-editing program should open up.  Add one line to this file containing the following:

source $(rvm 2.0.0 do rvm env --path)

Now, every time you open terminal, you are able to just do "rails" stuff right off the bat!  Neat!!!

Well, I hope this was able to help you.  If it was, then it's probably because I'm a complete amateur (right now, at least) in doing stuff on Linux, so I have to keep it simple (and without complex explanations that make no sense to noobs like me anyway).  I feel like if I had these step-by-step instructions, it would have saved me quite some time and frustration in getting Ruby on Rails set up and ready.