RubyGems
From DreamHost
Contents |
Installing a Local Copy of RubyGems
WARNING - Using your own version of RubyGems is not supported by DreamHost. You should not carry out these instructions unless you are prepared to fix any problems on your own. If you cannot do this and you need a newer version, please contact support to ask for an upgrade.
Installing your own copy of RubyGems is useful if you're using or writing software that depends on a higher version of RubyGems than is currently installed on DreamHost (0.9.5 as of 5/31/2008 -- see http://rails.dreamhosters.com for an updated list).
So let's get started. First we need to create the directories to store the RubyGems libraries and executables, and of course the gems themselves:
cd ~ mkdir .gems bin lib
Next, we need to set up paths so that the RubyGems libraries and executables you install will take precedence over the global installation. Open up ~/.bash_profile in your favorite text editor and insert these lines:
export PATH="$HOME/bin:$HOME/.gems/bin:$PATH" export RUBYLIB="$HOME/lib:$RUBYLIB" export GEM_HOME="$HOME/.gems" export GEM_PATH="/usr/lib/ruby/gems/1.8:$GEM_HOME" # this ensures our gem install processes don't get killed by the DreamHost police alias gem="nice -n19 ~/bin/gem"
To ensure that these changes get put into effect, log out and log back in.
Now let's install RubyGems. We could use the latest version (1.1.1 as of 31 May 2008) but for some reason it throws a bunch of errors, so we're going to go with 1.0.1:
cd ~/src wget http://rubyforge.org/frs/download.php/29548/rubygems-1.0.1.tgz tar xzvf rubygems-1.0.1.tgz cd rubygems-1.0.1 ruby setup.rb --prefix=$HOME
This will put the RubyGems libraries into ~/lib, and the gem executable in ~/bin. By default this executable is named "gem1.8" instead of "gem" as you might expect. So we need to make a symlink called "gem" that points to gem1.8:
cd ~/bin ln -s gem1.8 gem
Okay, now let's make sure the gem commands points to the one you just installed and has the right version:
which gem # should return /home/USERNAME/bin/gem gem -v # should return 1.0.1
If everything looks okay, you should be able to install your own gems and update gems that are already there. For example, you could update Rails with:
gem update rails
Installing/updating gems without installing gem
XXX: This needs to be condensed since it's repeating some of the above stuff
For those of you who don't need (or want) to install gems, there is another way you can use your own gems without the naughty-ness of installing gems (bloating your massive quota or just getting in your way or just no use for it) these are the steps to aid in the use of your own gems -- forwarning, using your own directory of gems (as with the above system) could break how ruby and ruby on rails runs. If a gem messes your site up, uninstall it.
First, you need to setup your .bash_profile. If you haven't already done it and make a directory for your gems.
mkdir .gems echo 'export GEM_HOME="$HOME/.gems"' >> .bash_profile echo 'export GEM_PATH="$GEM_HOME:/usr/lib/ruby/gems/1.8"' >> .bash_profile echo 'export PATH="$HOME/.gems/bin:$PATH"' >> .bash_profile
Of course, you could edit your .bash_profile using pico, nano or vi if you prefer. Then be sure to load all that:
source .bash_profile
If all goes well, you should be able to then install your own gems, update ones that are already there, and generally be a happier person. For example, you could update your rails gem with
gem update rails --include-dependencies
All of your personally-installed gems will end up in ~/.gems for you to use.
A few notes: Remember that with either a full gem install or using this technique, you need to use --include-dependencies to make sure all the dependencies are current. Be prepared, you can kill your ruby; if you do, you have gem uninstall, manually going into the .gems folder and deleting, or worst-case, deleting the whole .gems folder and starting again. Also, if you are using the Ruby on Rails platform, your "require" statements should list the full path of your personally installed rubygem. IE: require '/home/your_account/.gems/gems/activemerchant-0.6.0/lib/active_merchant'
Running gem install may get killed by the "tyrannical, but good-natured, procwatch daemon" while trying to resolve gem dependencies. A work-around is to install the gem manually and resolve the dependencies yourself. Download the gem file, then from the directory containing the gem run:
gem install --local gem_name
Adding the .gemrc File
If you get the error "Could not find RubyGem sources" when you attempt "gem install whatever", you'll need to add a .gemrc file.
touch ~/.gemrc
Add the following lines to the .gemrc file using your favorite editor. Be sure to add a newline at the end of the file.
gemhome: /home/USERNAME/.gems gempath: - /home/USERNAME/.gems - /usr/lib/ruby/gems/1.8
Application Specific Gems
Alternatively you can include gems in the vendor/plugins directory of your application. You can use the rake freeze task to move them there in your development environment and then just copy them over to Dreamhost.
Forcing your Application Search Path
You may find that your application will not pick up your personal gems from the bash environment. If you are still running into problems using custom gems, I recommend that you add something like the following to the top of your config/environment.rb file:
ENV['GEM_PATH'] = '/home/yourusername/.gems:/usr/lib/ruby/gems/1.8'
This should force your application to check your .gems directory before any of the public gems. I found this was necessary to use the Haml preprocessor plugin.
Other helpful stuff
To get around Permission Denied errors, check out - http://whynotwiki.com/Gems_/_How_to_install_to_your_home_directory

