RubyGems

Before You Make a Big Fish of a Small Fry
Just trying to install your own gems? You probably don't need to install RubyGems! Without any other messing around, try just installing whatever gems you need.

$ gem install mysql2 -v 0.3.7

If you're having trouble getting a Rails 3 application up and running, dive over to the Rails 3 article.

And hey, if your application isn't Rails, but it happens to have a Gemfile, you might want to give the following a try:

$ export PATH=~/.gems/bin:/usr/lib/ruby/gems/1.8/bin:$PATH $ bundle install $ bundle install --deployment

You can read more about Bundler and how it makes life a little easier over at the Bundler website.

http://gembundler.com/

If your application isn't currently using Bundler, you may want to consider adding Bundler to it!

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 (1.3.6 as of 9 October 2010). See http://rails.dreamhosters.com for a list of installed gems.

Note: The Dreamhosters list of RubyGems versions is out of date. To get the up-to-date list, ssh into your account and run:

gem 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  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: cd ~/.gem 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  in your favorite text editor and insert these lines:

export PATH="$HOME/bin:$HOME/.gems/bin:$PATH" export RUBYLIB="$HOME/lib:$RUBYLIB" (See Killed if having problems)

To ensure that these changes get put into effect, use the source command.

source ~/.bash_profile

Now let's install RubyGems (latest version 1.7.2 as of May 2011).

cd ~/src wget http://production.cf.rubygems.org/rubygems/rubygems-1.7.2.tgz tar xzvf rubygems-1.7.2.tgz cd rubygems-1.7.2 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
For those of you who don't need (or want) to install RubyGems, there is another way you can use your own gems without the naughty-ness of installing RubyGems (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  in your favorite text editor and insert this line:

export GEM_HOME="$HOME/.gems" export GEM_PATH="$GEM_HOME:/usr/lib/ruby/gems/1.8" export PATH="$HOME/.gems/bin:$PATH"

Also be sure the ".gems" directory exists.

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   install or using this technique, you need to use   to make sure all the dependencies are current. Be prepared, you can kill your ruby; if you do, you have, 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'. Or add a line to the beginning of your environment.rb file that looks like:

ENV['GEM_PATH'] = '/home/your_account/.gems:/usr/lib/ruby/gems/1.8'

Dabbling in this art can bring your rails app to its knees quickly. So take care, and remember you can always remove these changes in case something goes wrong.

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  and   are already created, and we are using   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  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  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.

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</tt>:

cd $RUN/bin ln -s gem1.8 gem

Okay, now let's make sure the gem</tt> 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
This section needs updating. There is another section on "Installing/updating gems without installing " above. It has information that may be useful.

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  in your favorite text editor and insert this line:

export PATH="$RUN/.gems/bin:$PATH"

To ensure that these changes get put into effect, use the source command.

source ~/.bash_profile

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   install or using this technique, you need to use   to make sure all the dependencies are current. Be prepared, you can kill your ruby; if you do, you have, 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 File
If you get the error "Could not find RubyGem sources" when you attempt "gem install whatever", you'll need to add a  file.

touch ~/.gemrc

Add the following lines to the  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  or   properly. I found I could still use them in vendor/plugins by copying the files from  (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  file:

ENV['GEM_PATH'] = '/home/yourusername/.gems:/usr/lib/ruby/gems/1.8'

This should force your application to check your  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