Project specific RubyGems

By Jan Veldeman

Using your distributions version of rubygems has some drawbacks:

  • root permission needed when installing gems
  • shared by all users
  • shared by all projects
  • when backing up a project, the system wide rubygems are often overlooked

Therefore, I’ve switched to project specific installations of rubygems (and one installation for everyday usage). By using modules it’s even easy to switch between projects.

First install ruby and some required dependencies:

sudo apt-get install ruby libyaml-ruby libzlib-ruby

Download and extract the latest rubygems version:

mkdir ruby_test
cd ruby_test
wget http://rubyforge.org/frs/download.php/35283/rubygems-1.1.1.tgz
tar zxvf rubygems-1.1.1.tgz

Create a modules file for easy loading:

#%Module1.0

set BASEDIR /path/to/ruby_test/rubygems

setenv RUBYOPT rubygems
setenv GEM_HOME ${BASEDIR}/gem_repository/
prepend-path PATH ${BASEDIR}/bin
prepend-path RUBYLIB ${BASEDIR}/lib

Note that the rubygems tarball extracted to rubygems-1.1.1, while the base directory is set to /path/to/ruby_test/rubygems. The rubygems-1.1.1 tree will be used to install rubygems into the latter directory.

If you named your module file ruby, you can now load it with:

module load ruby

With the environment variables set, install rubygems:

cd rubygems-1.1.1
ruby setup.rb --prefix=/path/to/ruby_test/rubygems

and clean up:

cd ../
rm -rf rubygems-1.1.1.tgz rubygems-1.1.1.

From this point on, you can use your newly installed rubygems, e.g. for installing wirble (tab completion and syntax coloring in irb).

gem list -r
gem install wirble

The RubyGems User Manual provides more information if needed.

Tags:

One Response to “Project specific RubyGems”

  1. Bart Caerts Says:

    Hi Jan,

    I had 2 issues trying to get this to work:
    1) when trying to do the install of rubygems, I got
    /usr/bin/ruby1.8: no such file to load — ubygems (LoadError)

    This is because RUBYOPT is already been defined, but not yet installed at right location. Running plain irb had the same issue.
    I solved this by unset this var before installing.

    2) During install I got the following trivial error:
    ./lib/rubygems/custom_require.rb:27:in `gem_original_require’: no such file to load — rdoc/rdoc (LoadError)
    from ./lib/rubygems/custom_require.rb:27:in `require’
    from setup.rb:51

    rubygems requires rdoc to be installed.
    This is something that the rubygems package has as a dependency (indirectly via libgems-ruby1.8).

Leave a Reply