Friday, October 26, 2012

Ruby on Rails with Ubuntu 10.4.4. lts

So I have been playing with RoR lately and have been muddling my way through a lot of an amazing tutorial by Michael Hartl found here: http://ruby.railstutorial.org/ruby-on-rails-tutorial-book
The tutorial is written the way I learn: with an end goal in sight. In a nutshell, you learn Ruby On Rails by developing Twitter. That is right, the book basically teaches you how to create Twitter (which, BTW, was written in RoR to begin with).

However, as much as I rave about the book it was not without complications. First off, it assumes you have some level of systems administration knowledge.
Though I completely agree with another reader's comment found in the tutorial (found here) getting set up the first time was a pain in the butt.
 I *am* a sysadmin (or at least played one in a former life) but I still had a lot of trouble getting the environment set up due to errors, missing libraries, and other random tidbits. I hunted down every last library not automatically installed by Ubuntu and put them into one command to install. I RULE!

So this entry is my cheat sheet to help you along with getting your Ubuntu 10.4.4 system set up to begin properly coding some RoR!
Many of the commands below are taken straight out of his book, there is little to no context in what I have written below, mostly just the commands.
There is a lot of formatting that I want to do to make this cleaner, but I knew that if I did not get this posted, I never would.

Assumptions:
You have a dedicated box on which to install a fresh operating system (never been used before)
OR
You have a virtual environment set up where you can install Linux as a fresh guest (preferred)
You are familiar with a CLI (Command Line Interface; similar to a DOS prompt)

You will need to get the proper distro which can be found by clicking here (Ubuntu 10.4.4 LTS 64bit)
If you want the 32 bit you can grab it by going here
I will heavily suggest using the 64bit version of Ubuntu. I have not tested any of these commands on the 32bit version.

I supply the specific commands you need to run to get everything done. If a line starts with a $ that is a command that needs to be run; you should be able to copy and paste the line into the Linux command line and be good to go (do not include the $). Pay attention to where the lines begin and end, this blog format makes it difficult to see easily. Also, you will notice I like to reboot a lot. I know this is not usually necessary in Linux, but my Windows background kicks in.

Demons run when a good man installs Ubuntu

Install Ubuntu 10.4 LTS on VMware (player or workstation get identical results). If you get errors about using the 64bit version of Ubuntu, you probably need to make changes to your bios. By default most PC systems do not turn on the 64bit virtualization key in the bios, so you will need to do it manually.
  • Using VMware most of the setup is automated.
  • Have at least 1GB RAM and 20gb HD, Also I prefer to have it use bridged networking
  • Install/update VMware tools if necessary (should already be up to date but it won't hurt to see)
  • Update Ubuntu (system>administration>update manager)
    • do NOT upgrade to Ubuntu 12.x LTS
  • Turn off screen saver and system lock (system>preferences>screensaver) not super necessary, it just bugs me.

If you are using VMware Workstation, it is always wise to take a snapshot at this point. I have had a couple of weird experiences that made it necessary to start over, a snapshot here would reduce a lot of time. VMware Player does not have the snapshot feature.
Also, in a VM, the Ethernet (eth0) likes to just disconnect itself here. Make sure it is connected.

Install these packages using the below command:
$ sudo aptitude install curl patch git-core build-essential autoconf automake bison build-essential libc6-dev libreadline6 libreadline6-dev libsqlite3-0 libsqlite3-dev libssl-dev libtool libxml2-dev libxslt-dev libyaml-dev ncurses-dev openssl sqlite3 subversion zlib zlib1g zlib1g-dev
Pay attention, you will be asked to provide your password and confirm installation of packages.
This will take a few minutes.
You used sudo here, close the terminal or reboot.

This section will get you through 1.2.2 of Michael Hartl's book.

Install ruby verison manager (RVM). Detailed instructions here https://rvm.io//
$ curl -L get.rvm.io | bash -s stable
$ source ~/.rvm/scripts/'rvm'
$ rvm requirements
$ echo '[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm"' >> ~/.bashrc

reboot

$ rvm get head && rvm reload
$ rvm install 1.9.3 This frequently failed to give expected results, so I used the below command instead.
$ rvm install 1.9.3 --with-openssl-dir=$HOME/.rvm.usr
You will need to quit out of the dialog that comes up (just hit the Q key).
This installation will take awhile, around 10+ minutes depending on the power of your host.
Reboot and check ruby version (looking to see that it confirms that ruby 1.9.3 is installed, it may say something like 1.9.3p286, this is acceptable)
$ ruby -v
The below command is run specifically for the tutorial, I forget what it does.
$ rvm use 1.9.3@rails3tutorial2ndEd --create --default
The below command tells me that the latest version is already installed... Meh, run it anyway... just in case.
$ gem update --system 1.8.24

Ruby is installed to this point but not Rails

$ gedit ~/.gemrc
Assuming you are at an Ubuntu desktop, this will open the gedit text editor and open the file ".gemrc". The file does not exist, so it will open a blank document. Fair warning, the dot in front of the filename (.gemrc) is supposed to be there; this signifies that the file is hidden.
add these 2 lines to the file:
install: --no-rdoc --no-ri
update: --no-rdoc --no-ri
Save the file and close gedit.

$ gem install rails -v 3.2.8

From here you can begin programming in rails. However, If you want to run the integrated rails server, you will need to install the below:

You will need the below for seciton 1.2.5

Installing Node.js via package manager to allow the rails server.
$ sudo apt-get install python-software-properties
$ sudo add-apt-repository ppa:chris-lea/node.js
$ sudo apt-get update
$ sudo apt-get install nodejs npm

You will need the below section for 1.3.4

Create a public SSH key (assuming you do not already ahve one, if this is a new install, you do not have one). Full tutorial here: https://help.github.com/articles/generating-ssh-keys
$ ssh-keygen -t rsa -C "your_email@youremail.com"
Just hit enter when asked about which file to save into.
Pick a passphrase, if this is a VM, you probably do not need to, but it is wise to get in the hapit and know where you would need to enter it in the future.
After the ssh key is created, you can sit on this until section 1.3.4 of Michael Hartl's book. (or create a github account, add the key, and test it, see the link earlier in this section for details)

You will need this section for 1.4.1

Install the heroku toolbelt (https://toolbelt.heroku.com/debian)
$ wget -qO- https://toolbelt.heroku.com/install-ubuntu.sh | sh
Login and create/add a public key (you will need a heroku account)
$ heroku login
$ heroku keys:add

This is an advanced section, you will need it for 3.5 excercise 3

Install additional repositories to get the appropriate version of postgres.
$ sudo add-apt-repository ppa:pitti/postgresql
$ sudo apt-get update
$ sudo apt-get install postgresql-9.1 postgresql-server-dev-9.1

No comments:

Post a Comment