AverageSecurityGuy

Security, Programming, Pentesting

About

Mastodon

Linked In

Projects

Cheat Sheets

Book

13 May 2011

Backtrack5 and Ruby 1.9.2

by {"login"=>"averagesecurityguy", "email"=>"stephen@averagesecurityguy.info", "display_name"=>"averagesecurityguy", "first_name"=>"", "last_name"=>""}

Update: I wrote this article before I realized that ubuntu and therefore BT5 comes with a script called update-alternatives. The update-alternatives script allows you to switch between different versions of java and ruby. If you are having trouble running a ruby script in BT5 try running update-alternative --config ruby and changing the ruby version. If that doesn't work then keep reading the rest of this article for other possible fixes.

I was playing around with BT5 today and noticed that it uses Ruby 1.9.2 as the default Ruby interpreter. Ruby 1.8 is installed as well if you would rather use it. To run a Ruby script using 1.8 just run ruby1.8 script.rb. If you come across a Ruby-based tool in BT5 that does not work then try running it using ruby1.8 before troubleshooting. If you want to run the script under Ruby 1.9.2 you may run into some problems I have listed a few below and how to fix them.

Problem 1: Load rubygems Before Loading Installed Gems

Often times when running a Ruby script that requires gems Ruby has to be told to load 'rubygems' before it loads installed gems. This can be done either by adding require 'rubygems' to each Ruby script before requireing other gems or by setting the environment variable RUBYOPT. To set the environment variable add the line export RUBYOPT="rubygems" to your .bashrc file in your home directory and then run source .bashrc

Problem 2: Tell Ruby Where to Find the Gems

For whatever reason Ruby cannot find the gems loaded for Ruby 1.9.2. To fix this set the environment variable GEM_HOME by adding the line export GEM_HOME=/var/lib/gems/1.9.2 to the .bashrc file in your home directory. You will need to run source .bashrc for the changes to take effect.

Problem 3: You cannot Require Files in the Current Directory

For security reasons Ruby 1.9.2 does not search the current directory when looking for required files. There are three options for dealing with this:

tags: Backtrack5 - ruby - ruby 1.9