Installing your own Ruby gems in a shared hosting environment

Although this is presumably a situation commonly encountered, it’s hard to find the instructions on how to install your own private gems in a shared hosting environment — where you don’t normally have root access.

Sorry, no super user access

Here are the steps:

  • Create your local gems directory:
$ mkdir /home/julian/gems
  • Find out the current environment settings for the installed Ruby gems:
$ gem environment
RubyGems Environment:
  - VERSION: 0.9.4 (0.9.4)
  - INSTALLATION DIRECTORY: /usr/local/lib/ruby/gems/1.8
  - GEM PATH:
     - /usr/local/lib/ruby/gems/1.8
  - REMOTE SOURCES:
     - http://gems.rubyforge.org
  • Create the startup file for Ruby gems to modify the search paths:
$ vi /home/julian/.gemrc
gemhome: /home/julian/gems
gempath:
- /home/julian/gems
- /usr/local/lib/ruby/gems/1.8
  • Add GEM_HOME and GEM_PATH to your shell startup file, which in my case is the .bashrc file:
$ vi /home/julian/.bashrc
...
GEM_HOME=/home/julian/gems
GEM_PATH=/home/julian/gems:/usr/local/lib/ruby/gems/1.8
export GEM_HOME GEM_PATH

With the above settings in place, you can now install and use your own private Ruby gems in your home directory.

Comment

Commenting is closed for this article.