Setting up Ubuntu Jaunty for Ruby and Rails development


Getting Ruby setup on Ubuntu – Jaunty

UPDATED: Added RSpec for Rails as well

Here are some quick steps to get you up and running with Ruby on Ubuntu, Take about 15 minutes depending on your internet connection.

Step 1: The first thing you need to do is update the packages in Ubuntu open the terminal window (Applications Menu | Accessories | Terminal) and type in the following commands.
   
   sudo aptitude update
   sudo aptitude dist-upgrade


Step 2: The next package will insure you have everything you need in order to build ruby packages on your system.
   
    sudo aptitude install build-essential

Step 3: Type in the following command to install Ruby NOTE: this is all ONE command

    sudo aptitude install ruby1.8-dev ruby1.8 ri1.8 rdoc1.8 irb1.8 libreadline-ruby1.8 libruby1.8 libopenssl-ruby


Step 4: Type in the following command to install SQLite3 NOTE: ONE command

    sudo aptitude install sqlite3 libsqlite3-ruby1.8


Step 5: Install Ruby Gems NOTE: Multiple commands
       
   wget http://rubyforge.org/frs/download.php/55066/rubygems-1.3.2.tgz
   tar xvzf rubygems-1.3.2.tgz
   cd rubygems-1.3.2
   sudo ruby setup.rb


!! You should get an error stating that Ruby command not found !!

Step 6: creating the ruby symlink (symlink stands for symbolic link, windows user can think of it like a shortcut)
       
   sudo ln -s /usr/bin/ruby1.8 /usr/local/bin/ruby

Step 7: Install ruby gems NOTE: you should be in the directory rubygems-1.3.2 when you run this command

    sudo ruby setup.rb

Step 8: We need to create the remaining symlinks for ruby utilities NOTE: Multiple commands

    sudo ln -s /usr/bin/gem1.8 /usr/local/bin/gem
    sudo ln -s /usr/bin/rdoc1.8 /usr/local/bin/rdoc
    sudo ln -s /usr/bin/ri1.8 /usr/local/bin/ri
    sudo ln -s /usr/bin/irb1.8 /usr/local/bin/irb

Installing Rails

Step 9: Install Rails

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

Step 10: Create a test project NOTE: Multiple commands

    cd ~
    mkdir apps
    cd apps
    mkdir rails_apps
    cd rails_apps
    rails testapp


Step 9: Start Webrick web server in your testapp directory

    ./script/server

Step 11: Open up Firefox and navigate to http://localhost:3000, you should see a page with the text:

    Welcome aboard
    You’re riding Ruby on Rails!


Step 12: Install Rspec
   
    gem install rspec

Installing source control

Step 13: Install subversion

    sudo aptitude install subversion


Step 14: Install Git because you are going to use plugins from GitHub

    sudo aptitude install git-core

Step 15: Install Git-svn

    sudo aptitude install git-svn

Step 16: Add SVN Like Shortcuts to Git

    git config --global alias.st status
    git config --global alias.ci commit
    git config --global alias.co checkout
    git config --global alias.br branch


Step 17: configure the global user for Git
   
    git config --global user.name "Put your full name here"
    git config --global user.email you@rackspace.com

Step 18: colorize the output for Git
   
    git config --global color.branch auto
    git config --global color.diff auto
    git config --global color.interactive auto
    git config --global color.status auto

 

Installing RSpec for Rails

I want to put a disclaimer here that this is my preferred way of installing RSpec from GitHub. It is not the only way.

Step 19: Navigate to the root of your Rails project. I am assuming that in this case it will be "testapp"

Step 20: Install Rspec for Rails from GitHub as Git submodules. NOTE: Multiple commands

git submodule add git://github.com/dchelimsky/rspec.git vendor/plugins/rspec

git submodule add git://github.com/dchelimsky/rspec-rails.git vendor/plugins/rspec-rails

Step 21: Run the rspec generators, this will enable the rspec_* controller, scaffold, model generators

ruby script/generate rspec

This is going to drive you nuts if you have to remember to do this for every rails project you create so I created a simple bash script.  Actually the contains more than the bash script it also has the aliases that I use for Rails development.

Step 22: Navigate to your home diretory

cd ~

Step 23: Create the .rails_aliases file

gedit .rails_aliases

Step 24: In gedit copy the following text to the .rails_aliases file

alias ror-doc-spec='open -a Firefox doc/plugins/rspec-rails/index.html'
alias ror-doc='open -a Firefox'
alias ror-scaffold='ruby script/generate rspec_scaffold'
alias ror-controller='ruby script/generate rspec_controller'
alias ror-model='ruby script/generate rspec_model'
alias ror-git-customerror='script/plugin install git://github.com/gumayunov/custom-err-msg.git'
alias ror-console='ruby script/console'
alias rapps='cd ~/apps/rails_apps'
alias ror-serv='ruby script/server'
alias ror-logtail='tail -f log/development.log'

# Configures a rails app to use rspec
specrails(){
        git submodule add git://github.com/dchelimsky/rspec.git vendor/plugins/rspec
        git submodule add git://github.com/dchelimsky/rspec-rails.git vendor/plugins/rspec-rails
        ruby script/generate rspec
}

Step 25: Save the file and close gedit

Step 26: Open your .bashrc file from the terminal window

gedit .bashrc

Step 27: Add the reference to your .rails_aliases file in your .bashrc at the top of the file add the following line:

source ~/.rails_aliases

Step 28: Save the file and exit gedit

Now if you want to add RSpec to any rails project you simply navigate to the root of a rails project and type:

specrails

If you want to add a controller with RSpec specs you simply have to type:

ror-controller BlogPost title:string author:string content:text ...

Hope this helps! Happy coding!


Posted May 06 2009, 11:06 AM by Joe Ocampo
Filed under: , ,

Comments

schambers wrote re: Setting up Ubuntu Jaunty for Ruby and Rails development
on 05-06-2009 12:46 PM

There is a new editor for ubuntu/linux that accepts textmate bundles. its called redcar editor:

http://redcareditor.com/

I personally use gedit with the gmate mod to make it more like textmate

Garry Shutler wrote re: Setting up Ubuntu Jaunty for Ruby and Rails development
on 05-06-2009 4:18 PM

I would recommend grabbing the rspec-rails gem as well. It has some specialised test helpers for testing controllers and so on.

Joe Ocampo wrote re: Setting up Ubuntu Jaunty for Ruby and Rails development
on 05-06-2009 6:35 PM

@schambers

Redcar has tremendous potential for Textmate users switching to Linux but it is still to Alpha for me.  But definitely on the radar.

Joe Ocampo wrote re: Setting up Ubuntu Jaunty for Ruby and Rails development
on 05-06-2009 6:36 PM

@Garry I was going to add that but ....oh hell never mind I will just update it.

:-)

Sean Biefeld wrote re: Setting up Ubuntu Jaunty for Ruby and Rails development
on 05-07-2009 10:58 AM

Excellent post, this will help me greatly!

gnubuntux wrote re: Setting up Ubuntu Jaunty for Ruby and Rails development
on 05-08-2009 9:14 PM

There's a metapackage called "ruby-full" ... just do

sudo apt-get install ruby-full

Ennuyer.net » Blog Archive » 2009-05-09- Today???s Ruby/Rails Reading wrote Ennuyer.net » Blog Archive » 2009-05-09- Today???s Ruby/Rails Reading
on 05-09-2009 5:55 AM

Pingback from  Ennuyer.net  » Blog Archive   » 2009-05-09- Today???s Ruby/Rails Reading

Setting up Ubuntu Jaunty for Ruby and Rails development | Ubuntu-News - Your one stop for news about Ubuntu wrote Setting up Ubuntu Jaunty for Ruby and Rails development | Ubuntu-News - Your one stop for news about Ubuntu
on 05-11-2009 6:12 PM

Pingback from  Setting up Ubuntu Jaunty for Ruby and Rails development | Ubuntu-News - Your one stop for news about Ubuntu

Theodore Wirth wrote re: Setting up Ubuntu Jaunty for Ruby and Rails development
on 05-11-2009 7:13 PM

Cool.  What the heck is "Ruby and Rails".  You don't even give the rest of us a clue as to what it is!  I still don't know what it is after reading the article and the posts.

Derek Neighbors wrote re: Setting up Ubuntu Jaunty for Ruby and Rails development
on 05-14-2009 2:14 PM

Thanks for the heads up on redcar.  

Add a Comment

(required)  
(optional)
(required)  
Remember Me?

Enter the numbers above:
Copyright Los Techies 2007, 2008. All rights reserved.
Powered by Community Server (Commercial Edition), by Telligent Systems