tags:

views:

185

answers:

3

I've cloned the ruby 1.8.7 source tree. I can build ruby. But I can't figure out how to run it without installing it in system directories. How can I do it?

Background: I want to use "git bisect" to figure out which build of Ruby introduced a new behavior in my code. I need to build and run ruby against a test program, multiple times, but I don't want to clobber the ruby that the Debian package installed.

Here's what I get if I try to run the ruby I built from source:

$ ./ruby -e 'puts RUBY_VERSION'
ÀÇ      ÀÇ      : ÀÇ    ÀÇ      : cannot open shared object file: No such file or directory - ÀÇ        ÀÇ       (LoadError)

I've also tried installing it, but not to the system directories, and got a stack trace:

$ ./configure --prefix=/home/wayne/tmp/ruby/installed --exec-prefix=/home/wayne/tmp/ruby/installed
$ make
$ make install
$ /home/wayne/tmp/ruby/installed/bin/ruby -e 'puts RUBY_VERSION'
/home/wayne/tmp/ruby/installed/lib/ruby/1.8/openssl/ssl.rb:26: uninitialized constant OpenSSL::SSL::VERIFY_PEER (NameError)
        from /home/wayne/tmp/ruby/installed/lib/ruby/1.8/openssl.rb:23:in `require'
        from /home/wayne/tmp/ruby/installed/lib/ruby/1.8/openssl.rb:23

I've got the feeling that I'm close, but a miss is as good as a mile.

+2  A: 

When I need to do something like that, I use the chroot command. Create a temporary directory, install ruby into a sbin subdirectory, and chroot into the temp folder. Depending on what you are testing, you may also have to copy some system libraries into the temporary directory tree (before you chroot in).

bta
A: 

It's probably easier to use rvm to test your app against different rubies.

Ben
+1  A: 

rvm is a great tool. and should be able to take care of the heavy lifting for switching between different ruby version (or even sets of gems).

Installation is very easy:

$ gem install rvm && rvm-install 
$ echo "if [[ ! -z $HOME/.rvm ]] ; then source $HOME/.rvm ; fi" >> ~/.bash_profile

Then to install a specific version & patch level:

rvm  install ruby-1.8.7-p160

Then to switch between versions:

$ rvm 1.8.7-p160 
$ ruby -v
ruby 1.8.7 (2009-06-12 patchlevel 160) [i686-darwin10.0.0]
$ rvm 1.8.7-p174 
ruby 1.8.7 (2009-06-12 patchlevel 174) [i686-darwin10.0.0]
csexton