Setup – Ruby & RVM


Overview

This is a quick article on how to setting up a Ruby environment running under Ruby Version Manager (RVM).  When I started on this road it took a while getting use to how everything fits together, so I hope this article will help someone out there.  It will be a growing document that will be added to and refined as I learn new things about this great tool.  What I’ll be going through are as follows:

  1. Pre-requisites
  2. Installing Ruby Version Manager (RVM)
  3. Installing Ruby under RVM
  4. Installing most required packages under the RVM
  5. Writing your first Ruby App
  6. Conclusion

Pre-requisites

Please refer to my article called “Setup – Requirements” for any pre-requisites.  I’ll keep that article live with any new packages that I think should be installed. 

Installing Ruby Version Manager (RVM)

This install is probably the easiest of them all J  In this case you can follow the steps on the main page of the RVM site or you could go through the site and do some of the other steps that Wayne has there.  RVM is probably one of the most important Ruby tools you’ll get yourself accustomed to and by going through the site and playing with Ruby you’ll quickly realize why I say that.  If you don’t feel like heading over to Wayne’s site then you can simply follow these steps.  To install RVM run the following command:

bash < <( curl http://rvm.beginrescueend.com/releases/rvm-install-head )

Now that you’ve installed it, you’ll have to make a few changes to some files on your file system to enable RVM to work properly and to be picked up when you start a Terminal.  First open the file “~/.bashrc” and do as follows:

  1. At the top of the file you should see:
    [ -z “$PS1” ] && return
    Replace this line with:

    if [[ -n “$PS1” ]] ; then
  2. Now go to the end of the file and enter a “fi” to close the “if” statement that we opened in step 1.
  3. After the closing “fi” statement enter the following line:
    [[ -s “$HOME/.rvm/scripts/rvm” ]] && source “$HOME/.rvm/scripts/rvm”

Now that that’s done open the file “~/.profile” and paste the following line at the end of the file:

[[ -s “$HOME/.rvm/scripts/rvm” ]] && source “$HOME/.rvm/scripts/rvm”

Once saved you should run the following command to refresh your environment with the settings you just added to the “~/.bashrc” file:

source ~/.bashrc

You should also run the following command to refresh your environment with the settings you added to the “~/.profile” file:

source ~/.profile

Once this is done you have RVM installed and you’re almost done 🙂  It should get easier from here on in.

Installing most required packages under the RVM

Now that you have your RVM environment set up you should install the most required packages before installing Ruby.  To do this simply type in the following command:

rvm package install ree_dependencies

Installing Ruby under RVM

As I said in the previous session, it only gets easier from here on in. Seeing that you have most of the dependencies installed under RVM you can now install Ruby quite easily by running the following command:

rvm install 1.9.2-p0

This will install Ruby version 1.9.2 with patch 0 (zero) for you in a new RVM called “ruby-1.9.2-p0”.  Once completed you can change your RVM context to use this version of Ruby by typing:

rvm use ruby-1.9.2-p0

Now if you type in “ruby –v” you should see the following text:

ruby 1.9.2p0 (2010-08-18 revision 29036) [i686-linux]

That simply confirms that Ruby has been installed and that your environment has been switched to use the specific RVM that you chose.

Writing your first Ruby App

Writing your first Ruby application can be achieved in a few easy steps.  First, browse to a folder that you would like to use for this first project.  In my case I’m using “~/projects/HelloWorld”.  Once there you should create a new ruby file and call it “hello_world.rb”.  To do this easily you can use the following command:

touch hello_world.rb

Now that you have your first Ruby file created you may want to add some code to it.  So open the file up in your favorite Text Editor (Gedit is mine) and type the following into it:

puts “Hello World

Close the Text Editor and run your Ruby app by running the following command:

ruby hello_world.rb

When you run the command above you should see something like:

Hello World

That’s it!!!  You’ve just run your very first Ruby app in the age old tradition of Hello World apps 🙂

Conclusion

You should now be in a position to start writing that Ruby code that you’ve wanted to write for some time.  I’ll also be doing some articles on some of the stuff that I’ve wanted to do and would like your feedback when I do.  I hope this helps those other guys out there that have gone through so many different sites and who haven’t yet been able to get all the information to a point where they can start coding…

Enjoy!!!

  1. No comments yet.
  1. No trackbacks yet.

Leave a comment