Thursday, September 15, 2011

Setting up Ubuntu for Rails Devlelopment

I had originally set up my Rails dev environment on Ubuntu Server in a Virtual Machine on VirtualBox, and I was accessing it from my main Ubuntu desktop via SSH and SFTP, however I decided to migrate to a Ubuntu Desktop VM, still wanting to keep it separated into a VM.

There are a few guides out there already, but I've followed instructions from several, and I just wanted to document my entire process here.

These instructions are intended for use on Ubuntu 11.10. This post will be updated as needed for new versions of Ubuntu and/or new or different installation methods.

First, a little housekeeping. In a terminal:


sudo apt-get update
sudo apt-get upgrade


Reboot now, and then come back to a terminal and:


sudo apt-get dist-upgrade


(If needed)
Reboot again if you did a dist-upgrade

Now, we need to install a couple of packages before we can install RVM:


sudo apt-get install git-core curl


Now, we can install RVM:

bash -s stable < <(curl -s https://raw.github.com/wayneeseguin/rvm/master/binscripts/rvm-installer)

Followed by:

echo '[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm" # Load RVM function' >> ~/.bashrc

Optionally, give yourself an awesome Bash prompt. Add the following to the bottom of your ~/.bashrc file:

PS1='\[\033[32m\]\u@\h\[\033[00m\]:\[\033[34m\]\w\[\033[31m\]$(__git_ps1)\[\033[00m\]\$ '

Followed by:

. .bashrc


(This will reset your bash config).

You will now have a color prompt which will tell you what Git branch you are on.

You can type rvm to enusre that RVM is loaded.


Now, we need to install a few more pre-req's:


sudo apt-get install libruby1.8 zlib1g-dev libssl-dev libreadline-gplv2-dev build-essential


Now, we can install Ruby 1.8.7:

rvm install 1.8.7

rvm use 1.8.7 --default


Now, we will add the Ubuntu on Rails PPA for a few other needed items:


sudo add-apt-repository ppa:ubuntu-on-rails

sudo apt-get update


Now for a few more installs:


sudo apt-get install ruby rubygems irb ri rdoc rake ruby1.8-dev libopenssl-ruby libxslt-dev libxml2-dev



Then:

export PATH=/var/lib/gems/1.8/bin:$PATH


Now, for SQLite3:

sudo apt-get install sqlite3 libsqlite3-dev

Followed by,

gem install sqlite3-ruby


Now, Ruby 1.9.3:

rvm install 1.9.3

rvm use 1.9.3 --default


If during the Ruby 1.9.3 install, you received errors about compiling yaml, try the following commands in succession:

rvm remove 1.9.3

rvm cleanup all

rvm get head

rvm reload

and then, again

rvm install 1.9.3

rvm use 1.9.3 --default

Now, install Rails

gem install rails


After you have both Rails and Ruby 1.9.2 up and running, install the sqlite gem again:


gem install sqlite3-ruby



Optionally, we can set up Sublime Text 2, the ultimate Rails editor (or you can use your editor of choice):

First, add an additional PPA Repository:

sudo apt-add-repository ppa:webupd8team/sublime-text-2

Followed by:

sudo apt-get update && sudo apt-get install sublime-text

If using Sublime Text 2, I recommend Ryan Bates' Railscast theme. See this earlier post for instructions on how to set that up, or any other Textmate theme you might prefer.

Whew! All done! We now have an Ubuntu desktop set up for Rails Development!

2 comments:

  1. This might be useful (maybe you saw it already): Detailed and up-to-date instructions for installing Rails 3.2: Read This Before Installing Rails 3.2.

    ReplyDelete