Tag Archives: Ruby

Speed up Ruby’s gem installation

You can skip the time and space consuming installations of the documentation and of the interactive reference that belong to Ruby gems. If you are sure that you don’t need these documents you can install a gem like this:

$ gem install <NAME_OF_THE_GEM> --no-ri --no-rdoc

To make this the default behavior for gem installations add this string to your gem configuration file (i.e. ~/.gemrc or /etc/gemrc):

gem: --no-ri --no-rdoc

Using the Ruby Version Manager (RVM)

Sometime you have to work with different versions of ruby (or jruby). This can be quite a pain but there is a remedy – the Ruby Version Manager (RVM). It helps you to handle many different ruby installations and their gems by installing them in a folder called .rvm in you home directory.

To install run the installation script

$ bash < <( curl http://rvm.beginrescueend.com/releases/rvm-install

and add this string e.g. to your .bashrc

[[ -s $HOME/.rvm/scripts/rvm ]] && source $HOME/.rvm/scripts/rvm

Now you can install some versions of ruby:

$ rvm install 1.8.7
$ rvm install 1.9.1

But wait!!! After installing it this way I ran later into a problem with OpenSSL in Rails (no such file to load -- openssl (RuntimeError)). So I followed the instructions regarding packages and installed the ruby version the in following manner with OpenSSL support:

rvm package install openssl
rvm install 1.9.1 -C --with-openssl-dir=$HOME/.rvm/usr
rvm install 1.8.7 -C --with-openssl-dir=$HOME/.rvm/usr

After that it is easy to switch between ruby versions. Without any specification the system wide configured ruby version is called:

$ ruby -v
ruby 1.8.7 (2010-01-10 patchlevel 249) [i486-linux]
$ which ruby
/usr/bin/ruby
$ which gem
/usr/bin/gem

Now we use rvm to switch to ruby 1.8.7

$ rvm 1.8.7
$ ruby -v
ruby 1.8.7 (2009-06-12 patchlevel 174) [i686-linux]
$ which ruby
/home/<your_username>/.rvm/rubies/ruby-1.8.7-p174/bin/ruby
$ which gem
/home/<your_username>/.rvm/rubies/ruby-1.8.7-p174/bin/gem

Now to ruby 1.9.1

$ ruby -v
ruby 1.9.1p378 (2010-01-10 revision 26273) [i686-linux]
$ which ruby
/home/<your_username>/.rvm/rubies/ruby-1.9.1-p378/bin/ruby
$ which gem 
/home/<your_username>/.rvm/rubies/ruby-1.9.1-p378/bin/gem

Installing gems for a specific version if also a piece of cake:

rvm 1.8.7 gem install rspec rails metric_fu

You can set default versions for different projects by adding a .rvmrc to the folders of your projects:

echo "rvm 1.8.7" > /path/to/my/project/.rvmrc