Local Gems and Goldberg

If you don't have administrator rights to the host on which you intend deploying Rails and Goldberg, you can still use Rubygems by setting up your own local gem repository.  This is especially applicable in shared hosting environments, where you won't necessarily have any control over which gems the administrator may choose to install.

Setting up your own local gems requires some initial work, but has long-term benefits.  Not only do you get to choose what gems you want now, you have the choice to upgrade them in the future at whatever time is convenient for you.

All the information in this document is also available elsewhere, but it's collected here for convenience.  Some of these steps reflect my own personal preferences or ways of doing things; you can of course modify these steps to suit your own requirements.

Installation of Rubygems

  1. Make a directory to hold your local Rubygems installation.  I also like to install the gem repository in the same place.  Set the appropriate environment variables.  (Replace /home/username with whatever path is appropriate for you, of course.)

    cd ~
    mkdir rubygems
    export GEM_HOME=/home/username/rubygems
    export GEM_PATH=/home/username/rubygems

    The environment variable GEM_PATH is applicable for the usage of the gems, while GEM_HOME is applicable for updates of your local gem repository (installing or upgrading gems, etc.).  It's the difference between reading and writing your repository.

  2. Make a directory for downloaded sources.  Download the latest version of Rubygems and install it.

    wget http://rubyforge.org/frs/download.php/17190/rubygems-0.9.2.tgz
    tar zxvf rubygems-0.9.2.tgz
    cd rubygems-0.9.2
    ruby setup.rb config --prefix="/home/username/rubygems/"
    ruby setup.rb setup
    ruby setup.rb install
  3. Prepend your new Rubygems bin/ directory to your PATH, so that it gets used in preference to the default.

    export PATH=/home/username/rubygems/bin:$PATH

    It would probably be convenient to add all three export commands shown above to your ~/.bashrc file so you can use and update gems from your local repository in future sessions.

You should now be prepared to install the goldberg_generator gem and install or upgrade your site(s).

Local Gems and Your Webserver

Rails tries to load itself from the gem from which it was originally installed.  Therefore your web server needs to have GEM_PATH set -- otherwise your Rails site will go looking for Rails in the system gem repository.  That won't work if your Rails gem is more recent than the system administrator's one.

If your hosting provider supports Apache's SetEnv directive you can use it in RAILS_ROOT/public/.htaccess.  Otherwise you can add the following line near the top of RAILS_ROOT/config/boot.rb (just under the comment that says, "Don't change this file").

ENV['GEM_PATH'] = '/home/username/rubygems'

 (Don't feel too guilty about editing RAILS_ROOT/config/boot.rb - you won't damage anything.  The advice to not edit that file exists because - as a matter of style - it is appropriate to put configuration settings for your application in RAILS_ROOT/config/environment.rb.  However by the time that file's loaded, it's already too late to set GEM_PATH, hence the need to put the above command in boot.rb.)


Login