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!
The non-Unix account setup way (install to ~)
So let's get started. First we need to create the directories to store the gems:
cd ~ mkdir .gems
Now, let's make sure our paths are updated so that the new gems folder will take precedence over the global installation. Open up ~/.bash_profile in your favorite text editor and edit these lines:
export GEM_HOME="$HOME/.gems" export GEM_PATH="$GEM_HOME:/usr/lib/ruby/gems/1.8"
If you are installing your own custom gem, you will need to read the following section as well.
Install gem
We need to create some more directories:
mkdir bin lib src
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"
# 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, use the source command.
source ~/.bash_profile
Now let's install RubyGems (latest version 1.3.0 as of Oct 2008).
cd ~/src wget http://rubyforge.org/frs/download.php/43985/rubygems-1.3.0.tgz tar xzvf rubygems-1.3.0.tgz cd rubygems-1.3.0 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.3.0
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 install rails
Installing/updating gems without installing gem
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.
Now, let's make sure our paths are updated so that the new gems folder will take precedence over the global installation. Open up ~/.bash_profile in your favorite text editor and insert this line:
export PATH="$HOME/.gems/bin:$PATH"
For example, you can now update your rails gem with:
gem install rails
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
The Unix Account Setup way
Since we are using the Unix account setup instructions, we will only need to create the .gems directory (since lib and bin are already created, and we are using soft to download and compile your sources):
cd $RUN mkdir .gems
Now, let's make sure our paths are updated so that the new gems folder will take precedence over the global installation. Open up ~/.bash_profile in your favorite text editor and edit these lines:
export GEM_HOME="$RUN/.gems" export GEM_PATH="$GEM_HOME:/usr/lib/ruby/gems/1.8"
If you are installing your own custom gem, you will need to read the following section as well.
Install gem
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="$RUN/.gems/bin:$PATH" export RUBYLIB="$RUN/lib:$RUBYLIB"
To ensure that these changes get put into effect, use the source command.
source ~/.bash_profile
Now let's install RubyGems (latest version 1.3.0 as of Oct 2008). We include alias to ensure our gem install processes don't get killed by the DreamHost police. Since this gem alias will break future usage of the gem command, we unalias it after our initial setup.
alias gem="nice -n19 $RUN/bin/gem" cd ~/soft wget http://rubyforge.org/frs/download.php/43985/rubygems-1.3.0.tgz tar xzvf rubygems-1.3.0.tgz cd rubygems-1.3.0 ruby setup.rb --prefix=$RUN unalias gem
This will put the RubyGems libraries into $RUN/lib, and the gem executable in $RUN/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 $RUN/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/run/USERNAME/bin/gem gem -v # should return 1.3.0
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 install rails
Installing/updating gems without installing gem
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.
Now, let's make sure our paths are updated so that the new gems folder will take precedence over the global installation. Open up ~/.bash_profile in your favorite text editor and insert this line:
export PATH="$RUN/.gems/bin:$PATH"
For example, you can now update your rails gem with:
gem install rails
All of your personally-installed gems will end up in $RUN/.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/run/.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.
Some plugins, such as haml, don't rake rails:freeze:gems or gem unpack properly. I found I could still use them in vendor/plugins by copying the files from /var/lib/gems/1.8/gems/gemname (or wherever your gems are located) to vendor/plugins.
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

